Difference between revisions of "Vote Simple"
Jump to navigation
Jump to search
(New page: {{LSL Header}} Simple voting script. One avi, one vote with a click. <lsl> // Voting script, only allows one vote per avi // @author JB Kraft // ------------------------------------------...) |
m (<lsl> tag to <source>) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 2: | Line 2: | ||
Simple voting script. One avi, one vote with a click. | Simple voting script. One avi, one vote with a click. | ||
< | <source lang="lsl2"> | ||
// Voting script, only allows one vote per avi | // Voting script, only allows one vote per avi | ||
// | // by JB Kraft | ||
// | string thankYouMessage = "Thanks for voting"; | ||
string floatText = "Vote for me!"; | |||
// _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ | |||
// _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ | |||
integer numberOfVotes; | |||
list listOfVoterNames; | |||
update_floattext() | |||
{ | { | ||
llSetText( | // set white and opaque floattext | ||
llSetText(floatText + "\n" | |||
+ (string)numberOfVotes + " votes", <1.0, 1.0, 1.0>, (float)TRUE); | |||
} | } | ||
integer added_vote(key id) | |||
integer | |||
{ | { | ||
// cut list if memory shortage | |||
if( llGetFreeMemory() < | if(llGetFreeMemory() < 5000) | ||
listOfVoterNames = llList2List(listOfVoterNames, -50, -1); | |||
string avatarLegacyName = llKey2Name(id); | |||
// TRUE if found, else FALSE | |||
// watch out, this is bit-wise NOT (~) not minus (-) | |||
integer thisAvatarHasVotedAlready = ~llListFindList(listOfVoterNames, [avatarLegacyName]); | |||
if (thisAvatarHasVotedAlready) | |||
return FALSE; | |||
// else | |||
// { | |||
listOfVoterNames += [avatarLegacyName]; | |||
numberOfVotes = llGetListLength(listOfVoterNames); | |||
update_floattext(); | |||
return TRUE; | return TRUE; | ||
// } | |||
} | } | ||
default | default | ||
{ | { | ||
on_rez(integer start_param) | |||
{ | |||
llResetScript(); | |||
} | |||
state_entry() | state_entry() | ||
{ | { | ||
update_floattext(); | |||
} | } | ||
touch_start(integer num_detected) | |||
touch_start(integer | |||
{ | { | ||
key id = llDetectedKey(0); | |||
if( added_vote(id) && thankYouMessage != "" ) | |||
llInstantMessage(id, thankYouMessage); | |||
} | } | ||
} | } | ||
</source> | |||
</ | |||
{{LSLC|Library|Vote Simple}}{{LSLC|Examples|Vote Simple}} | {{LSLC|Library|Vote Simple}}{{LSLC|Examples|Vote Simple}} |
Latest revision as of 18:16, 24 January 2015
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Simple voting script. One avi, one vote with a click.
// Voting script, only allows one vote per avi
// by JB Kraft
string thankYouMessage = "Thanks for voting";
string floatText = "Vote for me!";
// _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
integer numberOfVotes;
list listOfVoterNames;
update_floattext()
{
// set white and opaque floattext
llSetText(floatText + "\n"
+ (string)numberOfVotes + " votes", <1.0, 1.0, 1.0>, (float)TRUE);
}
integer added_vote(key id)
{
// cut list if memory shortage
if(llGetFreeMemory() < 5000)
listOfVoterNames = llList2List(listOfVoterNames, -50, -1);
string avatarLegacyName = llKey2Name(id);
// TRUE if found, else FALSE
// watch out, this is bit-wise NOT (~) not minus (-)
integer thisAvatarHasVotedAlready = ~llListFindList(listOfVoterNames, [avatarLegacyName]);
if (thisAvatarHasVotedAlready)
return FALSE;
// else
// {
listOfVoterNames += [avatarLegacyName];
numberOfVotes = llGetListLength(listOfVoterNames);
update_floattext();
return TRUE;
// }
}
default
{
on_rez(integer start_param)
{
llResetScript();
}
state_entry()
{
update_floattext();
}
touch_start(integer num_detected)
{
key id = llDetectedKey(0);
if( added_vote(id) && thankYouMessage != "" )
llInstantMessage(id, thankYouMessage);
}
}