OK Lets try this again!
list dances = ["dance 1","dance 2","dance 3","dance 4","dance 5"];
list current_dances = []; //This will be a list of all the dances currently playing
list select_menu = ["Start Dance", "Stop Dance"]; //This will let you choose wheter to start or stop a dance I just put it here to make it easier if you want to change the terminology
string dance_chosen;
key avatar;
integer channel; //This is the channel you will talk to the HUD on
integer listener; //This will tell us whether or not the hud is currently listenting - it just cuts down on lag
float listening_time = 300; //This is the amount of seconds the listener will remain active before timing out to cut down on lag - 300 is 5 minutes.
default
{
state_entry()
{
channel = llFloor(llFrand(999)) + 100; //This gives you a random number from 100 to 1099 - the llFrand gives you a random decimal and the llFloor makes it into an integer
}
touch_start(integer total_number)
{
avatar = llDetectedKey(0);
llDialog(avatar, "Would you like to stop a dance or start a dance?", select_menu, channel); //Now here I changed the channel you were talking on from 11 to channel - this is so that you can have different dance boxes talking on different channels - really only appropriate if you have them out for multiple people to use but force of habit on my part *grin*
if(listener == FALSE)
{
listener = llListen(channel,"",NULL_KEY,""

; //Again I changed the channel from 11 to channel
}
llSetTimerEvent(listening_time); //This restarts the listener for a full five mintues every time you touch the hud.
}
listen(integer channel, string name, key id, string message)
{
if(message == "Start Dance"
{
llDialog(avatar, "Which dance would you like to start?", dances, channel);
}
else if(message == "Stop Dance"

{
llDialog(avatar, "Which dance would you like to stop?", current_dances, channel);
}
//Now here we start living on the edge! *grin* Basically there are only two choices for each dance. Either you ARE doing them or you ARENT. So what we are going to do is figure out which list the dance is in, and then react appropriately and not worry about keeping track of which is which. Others may well script this differently and better but this is the way I do it *grin*
else if(llListFindList(dances, [message]) != -1)
{
dance_chosen = message;
llRequestPermissions(avatar,PERMISSION_TRIGGER_ANIMATION);
current_dances = current_dances + [message];
integer marker = llListFindList(dances, [message]);
llDeleteSubList(dances, marker, marker);
}
//This said - if you CAN find what we've asked for in the list of dances (that is, its position in the list is NOT -1), then we obviously arent doing it so you obviously want to start it.. so we'll start dancing, add it to the list of dances and take it off of the list of available dances. Now here's the thing.. if you are setting this out for multiple people to use and not using this as a hud this is not the best idea because it makes the dance unavailable for the next person coming along. Yes I did just think of that while I was scripting this. Ahh the joys of fluid scripting!!
else if(llListFindList(current_dances, [message]) != -1)
{
dances = dances + [message];
if(llGetPermissions() == PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation(message);
}
integer marker = llListFindList(current_dances, [message]);
llDeleteSubList(current_dances, marker, marker);
}
//This says if, instead we find the dance mentioned on the list of dances being done, then we put it back on the list of available dances, check to make sure that we have permission (I know, I know but you'd be surprised how many times that can come back to bite you in the posterior!) stop the dance and take it off of the list of dances currying boogeying on down.
}
run_time_permissions(integer perm)
{
if(PERMISSION_TRIGGER_ANIMATION & perm)
{
llStartAnimation(dance_chosen);
}
}
timer()
{
llListenRemove(listener);
llSetTimerEvent(0);
//If you havent changed anything for five mintues the listener will assume you are quite happy and quit listening until you touch it again.
}
}