Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

confused over if..else if while using llDialog

Owner Maltese
Registered User
Join date: 13 Sep 2005
Posts: 65
11-08-2005 05:58
I'm having trouble with this script I wrote. It's a "remote control" of sorts to a chair that does several things. I want to be able to limit the number of times it can be used and certain functions of the chair needs to be activiated. I have a general remote (that is supposed to work all six chairs) and a specific remote (that controls only one chair).

Here's the general remote script

CODE


integer buttonone;
integer buttontwo;
integer buttonthree;
integer buttonfour;
integer buttonfive;
integer buttonsix;
integer mistone;
integer misttwo;
integer mistthree;
integer mistfour;
integer mistfive;
integer mistsix;
integer connectorsone;
integer connectorstwo;
integer connectorsthree;
integer connectorsfour;
integer connectorsfive;
integer connectorssix;
integer moveone;
integer movetwo;
integer movethree;
integer movefour;
integer movefive;
integer movesix;
integer reminderson;
integer sayingson;
integer thoughtson;
integer uses;
integer limit = 36000; //36 - Each seat once.
integer LISTENCHANNEL = 3000; //dialog channel
integer MISTCHANNEL = 3010; // mist mist channel
integer THOUGHTSCHANNEL = 3011; //listen channel
integer SAYINGSCHANNEL = 3012; //sayings channel
integer CHANTCHANNEL = 3013; //chat channel
list MENU_SEATVOICE = ["activate one", "deactivate one", "activate two", "deactivate two", "activate three", "deactivate three", "activate four", "deactivate four", "activate five", "deactivate five", "activate six", "deactivate six"];
list MENU_OPTIONS = ["Seat Five", "Seat Six", "All Seats", "Seat Two", "Seat Three", "Seat Four", "Seat One" ]; // the sub menu
list MENU_MAIN = ["Reminders", "Sayings", "Thoughts", " Mist", "Connectors", "Move"]; //the Main menu


default
{
state_entry()
{
buttonone = 0;
buttontwo = 0;
buttonthree = 0;
buttonfour = 0;
buttonfive = 0;
buttonsix = 0;
mistone = 0;
misttwo = 0;
mistthree = 0;
mistfour = 0;
mistfive = 0;
mistsix = 0;
connectorsone = 0;
connectorstwo = 0;
connectorsthree = 0;
connectorsfour = 0;
connectorsfive = 0;
connectorssix = 0;
moveone = 0;
movetwo = 0;
movethree = 0;
movefour = 0;
movefive = 0;
movesix = 0;
reminderson = 0;
sayingson = 0;
thoughtson = 0;
uses = 0;
llListen(LISTENCHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users)
}

touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "You've used The Factory " + (string)uses + " times. \nPick a Seat Function.", MENU_MAIN, LISTENCHANNEL); // present dialog on click
}

listen(integer channel, string name, key id, string message)
{
if (llListFindList(MENU_MAIN + MENU_OPTIONS + MENU_SEATVOICE, [message]) != -1) // verify dialog choice
{
llSay(0, name + " picked " + message + "."); // output the answe
{
if (message == "activate one")
{
buttonone = 1;
}
else if (message == "deactivate one")
{
buttonone = 0;
}
else if (message == "activate two")
{
buttontwo = 1;
}
else if (message == "deactivate two")
{
buttontwo = 0;
}
else if (message == "activate three")
{
buttonthree = 1;
}
else if (message == "deactivate three")
{
buttonthree = 0;
}
else if (message == "activate four")
{
buttonfour = 1;
}
else if (message == "deactivate four")
{
buttonfour = 0;
}
if (message == "activate five")
{
buttonfive = 1;
}
else if (message == "deactivate five")
{
buttonfive = 0;
}
else if (message == "activate six")
{
buttonsix = 1;
}
else if (message == "deactivate six")
{
buttonsix = 0;
}
else if (message == " Mist")
{
llDialog(id, "Pick a seat", MENU_OPTIONS, LISTENCHANNEL);
if (message == "Seat One")
{
if (buttonone == 1)
{
if (mistone == 0)
{
if (uses < limit)
{
llSay(0,"Seat One Mist On");
llSay(3001,"mist seat on");
uses = uses + 1;
mistone = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat One Mist Off");
llSay(3001,"mist seat off");
mistone = 0;
}
}
else
{
llOwnerSay("Seat One not activated");
}
}
if (message == "Seat Two")
{
if (buttontwo == 1)
{
if (misttwo == 0)
{
if (uses < limit)
{
llSay(0,"Seat Two Mist On");
llSay(3002,"mist seat on");
uses = uses + 1;
misttwo = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Two Mist Off");
llSay(3002,"mist seat off");
misttwo = 0;
}
}
else
{
llOwnerSay("Seat Two not activated");
}
}
if (message == "Seat Three")
{
if (buttonthree == 1)
{
if (mistthree == 0)
{
if (uses < limit)
{
llSay(0,"Seat Three Mist On");
llSay(3003,"mist seat on");
uses = uses + 1;
mistthree = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Three Mist Off");
llSay(3003,"mist seat off");
mistthree = 0;
}
}
else
{
llOwnerSay("Seat Three not activated");
}
}
if (message == "Seat Four")
{
if (buttonfour == 1)
{
if (mistfour == 0)
{
if (uses < limit)
{
llSay(0,"Seat Four Mist On");
llSay(3004,"mist seat on");
uses = uses + 1;
mistfour = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Four Mist Off");
llSay(3004,"mist seat off");
mistfour = 0;
}
}
else
{
llOwnerSay("Seat Four not activated");
}
}
if (message == "Seat Five")
{
if (buttonfive == 1)
{
if (mistfive == 0)
{
if (uses < limit)
{
llSay(0,"Seat Five Mist On");
llSay(3005,"mist seat on");
uses = uses + 1;
mistfive = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Five Mist Off");
llSay(3005,"mist seat off");
mistfive = 0;
}
}
else
{
llOwnerSay("Seat Five not activated");
}
}
if (message == "Seat Six")
{
if (buttonsix == 1)
{
if (mistsix == 0)
{
if (uses < limit)
{
llSay(0,"Seat Six Mist On");
llSay(3006,"mist seat on");
uses = uses + 1;
mistsix = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Six Mist Off");
llSay(3006,"mist seat off");
mistsix = 0;
}
}
else
{
llOwnerSay("Seat Six not activated");
}
}
}
else if (message == "Connectors")
{
llDialog(id, "Pick a seat", MENU_OPTIONS, LISTENCHANNEL);
if (message == "Seat One")
{
if (buttonone == 1)
{
if (connectorsone == 0)
{
if (uses < limit)
{
llSay(0,"Connecting Connectors in Seat One");
llSay(3001,"connect");
uses = uses + 1;
connectorsone = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Disconnecting Connectors in Seat One");
llSay(3001,"connect");
connectorsone = 0;
}
}
else
{
llOwnerSay("Seat One not activated");
}
}
else if (message == "Seat Two")
{
if (buttontwo == 1)
{
if (connectorstwo == 0)
{
if (uses < limit)
{
llSay(0,"Connecting Connectors in Seat Two");
llSay(3002,"connect");
uses = uses + 1;
connectorstwo = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Disconnecting Connectors in Seat Two");
llSay(3002,"connect");
connectorstwo = 0;
}
}
else
{
llOwnerSay("Seat Two not activated");
}
}
else if (message == "Seat Three")
{
if (buttonthree == 1)
{
if (connectorsthree == 0)
{
if (uses < limit)
{
llSay(0,"Connecting Connectors in Seat Three");
llSay(3003,"connect");
uses = uses + 1;
connectorsthree = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Disconnecting Connectors in Seat Three");
llSay(3003,"connect");
connectorsthree = 0;
}
}
else
{
llOwnerSay("Seat Three not activated");
}
}
else if (message == "Seat Four")
{
if (buttonfour == 1)
{
if (connectorsfour == 0)
{
if (uses < limit)
{
llSay(0,"Connecting Connectors in Seat Four");
llSay(3004,"connect");
uses = uses + 1;
connectorsfour = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Disconnecting Connectors in Seat Four");
llSay(3004,"connect");
connectorsfour = 0;
}
}
else
{
llOwnerSay("Seat Four not activated");
}
}
else if (message == "Seat Five")
{
if (buttonfive == 1)
{
if (connectorsfive == 0)
{
if (uses < limit)
{
llSay(0,"Connecting Connectors in Seat Five");
llSay(3005,"connect");
uses = uses + 1;
connectorsfive = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Disconnecting Connectors in Seat Five");
llSay(3005,"connect");
connectorsfive = 0;
}
}
else
{
llOwnerSay("Seat Five not activated");
}
}
else if (message == "Seat Six")
{
if (buttonsix == 1)
{
if (connectorssix == 0)
{
if (uses < limit)
{
llSay(0,"Connecting Connectors in Seat Six");
llSay(3006,"connect");
uses = uses + 1;
connectorssix = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Disconnecting Connectors in Seat Six");
llSay(3006,"connect");
connectorssix = 0;
}
}
else
{
llOwnerSay("Seat Six not activated");
}
}
}
else if (message == "Move")
{
llDialog(id, "Pick a seat", MENU_OPTIONS, LISTENCHANNEL);
if (message == "Seat One")
{
if (buttonone == 1)
{
if (moveone == 0)
{
if (uses < limit)
{
llSay(0,"Seat One Move On");
llSay(3001,"move 1");
llSay(3000,"movebuttonon");
uses = uses + 1;
moveone = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat One Move Off");
llSay(3001,"stop");
llSay(3000,"movebuttonoff");
moveone = 0;
}
}
else
{
llOwnerSay("Seat One not activated");
}
}
else if (message == "Seat Two")
{
if (buttontwo == 1)
{
if (movetwo == 0)
{
if (uses < limit)
{
llSay(0,"Seat Two Move On");
llSay(3002,"move 1");
llSay(3000,"movebuttonon");
uses = uses + 1;
movetwo = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Two Move Off");
llSay(3002,"stop");
llSay(3000,"movebuttonoff");
movetwo = 0;
}
}
else
{
llOwnerSay("Seat Two not activated");
}
}
if (message == "Seat Three")
{
if (buttonthree == 1)
{
if (movethree == 0)
{
if (uses < limit)
{
llSay(0,"Seat Three Move On");
llSay(3003,"move 1");
llSay(3000,"movebuttonon");
uses = uses + 1;
movethree = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Three Move Off");
llSay(3003,"stop");
llSay(3000,"movebuttonoff");
movethree = 0;
}
}
else
{
llOwnerSay("Seat Three not activated");
}
}
else if (message == "Seat Four")
{
if (buttonfour == 1)
{
if (movefour == 0)
{
if (uses < limit)
{
llSay(0,"Seat Four Move On");
llSay(3004,"move 1");
llSay(3000,"movebuttonon");
uses = uses + 1;
movefour = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Four Move Off");
llSay(3004,"stop");
llSay(3004,"movebuttonoff");
movefour = 0;
}
}
else
{
llOwnerSay("Seat Four not activated");
}
}
else if (message == "Seat Five")
{
if (buttonfive == 1)
{
if (movefive == 0)
{
if (uses < limit)
{
llSay(0,"Seat Five Move On");
llSay(3005,"move 1");
llSay(3000,"movebuttonon");
uses = uses + 1;
movefive = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Five Move Off");
llSay(3005,"stop");
llSay(3000,"movebuttonoff");
movefive = 0;
}
}
else
{
llOwnerSay("Seat Five not activated");
}
}
else if (message == "Seat Six")
{
if (buttonsix == 1)
{
if (movesix == 0)
{
if (uses < limit)
{
llSay(0,"Seat Six Move On");
llSay(3006,"move 1");
llSay(3000,"movebuttonon");
uses = uses + 1;
movesix = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Six Move Off");
llSay(3006,"stop");
llSay(3000,"movebuttonoff");
movesix = 0;
}
}
else
{
llOwnerSay("Seat Six not activated");
}
}
}
else if (message == "Reminders")
{
if (reminderson = 0)
{
if (uses < limit)
{
llSay(0,"Reminders On");
llSay(CHANTCHANNEL,"hitreminderson");
uses = uses + 1;
reminderson = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Reminders Off");
llSay(REMINDERSCHANNEL,"hitremindersoff");
reminderson = 0;
}
}
else if (message == "Sayings")
{
if (sayingson == 0)
{
if (uses < limit)
{
llSay(0,"Sayings On");
llSay(SAYINGSCHANNEL,"hitsayingson");
uses = uses + 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Sayings Off");
llSay(SAYINGSCHANNEL,"hitsayingsoff");
}
}
else if (message == "Thoughts")
{
if (thoughtson == 0)
{
if (uses < limit)
{
llSay(0,"Thoughts On");
llSay(THOUGHTSCHANNEL,"hitthoughtson");
uses = uses + 1;
thoughtson = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Thoughts Off");
llSay(THOUGHTSCHANNEL,"hitthoughtson");
thoughtson = 0;
}
}
}
}
else
{
llSay(0, name + " picked invalid option '" + llToLower(message) + "'."); // not a valid dialog choice
}
}
}



The trouble with this script is that it seems like it will not go down the if...else if tree. It seems to do the first couple of things but then stop. For instance it will start the "sayings" but then it will not stop them. Just seems to go dead.

So I tried this with individual chair controls and this had a wierder problem.

CODE

//seat 6 script

integer listen_handle;
integer activateon;
integer limit = 10000;
integer miston;
integer connectorson;
integer moveon;
integer uses;
list MENU_MAIN = ["Mist", "Connectors", "Move", "Activate Seat", "Deactivate Seat"]; //the Main menu

seatactivator()
{
llSetColor(<1,1,1>,ALL_SIDES);
llSay(3016,"activate six");
activateon = 1;
}

seatdeactivator()
{
llSetColor(<0.5,0.5,0.5>,ALL_SIDES);
llSay(3016,"deactivate six");
activateon = 0;
}

activatemist();
{
if (activateon == 1)
{
if (miston == 0)
{
if (uses < limit)
{
llSay(0,"Seat Six Mist On");
llSay(3006,"mist seat on");
uses = uses + 1;
miston = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Six Mist Off");
llSay(3006,"mist seat off");
miston = 0;
}
}
else
{
llOwnerSay("Seat Six not activated");
}
}

connectconnectors();
{
if (activateon == 1)
{
if (connectorson == 0)
{
if (uses < limit)
{
llSay(0,"Connecting Connectors to Subject in Seat Six");
llSay(3006,"connect");
uses = uses + 1;
connectorson = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Disconnecting Connectors from Subject in Seat Six");
llSay(3006,"connect");
connectorson = 0;
}
}
else
{
llOwnerSay("Seat Six not activated");
}
}

startmove();
{
if (activateon == 1)
{
if (moveon == 0)
{
if (uses < limit)
{
llSay(0,"Seat Six Move On");
llSay(3006,"move 1");
llSay(3016,"movebuttonon");
uses = uses + 1;
moveon = 1;
}
else
{
llOwnerSay("Sorry, you've reached the limit");
}
}
else
{
llSay(0,"Seat Six Move Off");
llSay(3006,"stop");
llSay(3016,"movebuttonoff");
moveon = 0;
}
}
else
{
llOwnerSay("Seat Six not activated");
}
}

default
{
state_entry()
{
uses = 0;
miston = 0;
connectorson = 0;
moveon = 0;
activateon = 0;
llListenRemove(listen_handle);
listen_handle = llListen(3016,"",NULL_KEY,"");
}
listen(integer channel, string name, key id, string message)
{
if (llListFindList(MENU_MAIN, [message]) != -1) // verify dialog choice
{
llSay(0, name + " picked the option '" + message + "'."); // output the answer
if (message == "Activate Seat")
{
seatactivator();
}
else if (message == "Deactivate Seat")
{
seatdeactivator();
}
else if (message = "Mist")
{
activatemist();
}
else if (message == "Connectors")
{
connectconnectors();
}
else if (message == "Move")
{
startmove();
}
}
else
{
llSay(0, name + " picked invalid option '" + llToLower(message) + "'."); // not a valid dialog choice
}
}
touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "Choose a Seat function", MENU_MAIN, 3016); // present dialog on click
}
}



The problem with this one is that it will activate & deactivate the seat, activate and deactivate the Mist, but the other two buttons just activate and deactivate the Mist. That's it. I am going to add the other options, but why bother if it won't go beyond the Mist option.

I know these are cumbersome scripts but I'd apperciate any help you can give Me.

Thanks in advance.
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
11-08-2005 06:42
if-else

"Note: Only up to 23 else statements may be in a conditional chain. (a total of 24 conditionals: 1 if and 23 elses) Any more, and a syntax error will occur when the script is saved/compiled. However, a workaround to this is to nest conditionals, or, if that's not possible, unlink the conditional chain and use a series of distinct if statements: at the end of each if(){} block, put a jump or return as the last statement so that the remaining if statements that would have otherwise been "else if" statements are skipped."

You may need to trim your code a bit.

*edit* by my count, you have about 156 if else flow controls.
_____________________
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
11-08-2005 07:02
Two problems.
In your first chunk of code:
CODE
else if (message == " Mist") 
{
llDialog(id, "Pick a seat", MENU_OPTIONS, LISTENCHANNEL);
if (message == "Seat One")
after calling llDialog you are still in the event handler for the first response - that is, message is still equal to "Mist". Only after you exit the event will the listen event handler be called again (from the start) and you will have to check for "Seat One" etc.
You may find it easier, rather than checking for "Seat One" or "Seat Two" or "Deactivate One" etc, to split the string into "tokens" (see llParseString2List ) and then check the first element for "Seat" or "Deactivate" for example, and then check the second element for "one" or "two" and so on.

In the second piece of code, you have a simple (but common) typo:
CODE
else if (message == "Deactivate Seat") 
{
seatdeactivator();
}
else if (message = "Mist") // <- should be ==, not =
{
activatemist();
}
else if (message == "Connectors")
Val Fardel
Registered User
Join date: 11 Oct 2005
Posts: 90
11-09-2005 08:46
Yeah,

else if (message = "Mist";)

will set message = "Mist" and since that is TRUE. Since message is now "Mist" nothing after will be done.