Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

IF within IF

Prano Quan
Registered User
Join date: 15 Aug 2008
Posts: 29
08-25-2009 02:17
Hello fellow SL users,

I'm in need of help. My design of script isn't giving what I want. Let me start by telling you what I want. Simply put, I want the user to undergo levels of IF within IF, within IFs... ---> so on. These also need to be user inputs, back in C++, it is simply the command "cin < input_integer/string/etc" which acts as user-input, the small piece of puzzle I'm looking for:

//introduce all parameters such as
string userinput1;
string userinput2;
etc...

//llListen function to listen for user input
//First user input
if(userinput1 == "user_input_level1";)
llSay (You've entered level 1)

//Now, provided that the user has entered level 1, he/she can enter level 2 function
//second input
if (userinput2 == "user_input_level2";)
llSay(You've entered level 2)

And the situation continues

So, basically, what I'm confused about is making a NESTED-IF statements, SL allowed me to through user first input, but beyond that, I can't figure out how to allow further inputs to be affected (based on "provided user has inserted first level";)

Yes, I've made a situation where it's all IF functions, unfortunately that's not what I want, the user HAS to input the first command before getting allowance to second level of IF function.

I'm afraid I've lost you back then.. please let me know if this post is confusing, I'm sorry but I'm trying to make it understandable! Thank you very much in advance for your help!
Carbon Philter
Registered User
Join date: 4 Apr 2008
Posts: 165
08-25-2009 02:20
Wrong forum for help on this - best go to the Scripting Tips. Helpful people there may have more insight that I can offer.
Also, maybe the wiki can help - http://lslwiki.net/lslwiki/wakka.php?wakka=ifelse
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-25-2009 03:07
From: Prano Quan
So, basically, what I'm confused about is making a NESTED-IF statements, SL allowed me to through user first input, but beyond that, I can't figure out how to allow further inputs to be affected (based on "provided user has inserted first level";)


if(something) { // { means "start block here"
thingy();
if(something_else) { // nested block
thongy();
} // end nested block
} // end outer block
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Rhonda Huntress
Kitteh Herder
Join date: 21 Dec 2008
Posts: 1,823
08-25-2009 05:57
and do not forget, there is also "else" statement.


if(blah){
llDoThis();
}
else if (blahblah){
llDoThat();
}
else{
CatchException()
}


The LSL Portal is a great resource for scripting.
http://wiki.secondlife.com/wiki/LSL_Portal

There is also the lslwiki.net but it is pretty much the same thing. Use which ever you prefer.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
08-25-2009 10:05
In case you didn't figure it out from above, the curly braces are the key. "{" and "}".

Also, to see the code indented the way it was written in the posts, hit the "Quote" button for the post.
Kelli May
karmakanic
Join date: 7 Oct 2006
Posts: 1,135
08-25-2009 11:38
Accurate as that info is, I suspect its not all that helpful to the OP.

By the looks of it, he needs to check if previous inputs have been received, based on the results of a Listen event. So after receiving the first Listen message, he can then wait for a second (and maybe a third, fourth, nth).

At the time the program gets the nth message, the value of the first will not be available for comparison unless it's been stored or a flag set.


So (simplified):

listen(message)
{
if(message == first_input)
{
set first_input_flag;
say "Level 1";
}

if(message == second input && first_input_flag)
{
say "Level 2";
}
}

You could avoid flags by using a separate state for each level:

default
{

listen(message)
{
if(message == first_input)
{
say "level 1";
state level2;
}
}

}


state level2
{

listen(message)
{
if(message == second_input)
{
say "level 2";
}
}

}

edit: should have left this for the scripting forum.
_____________________
Do worried sheep have nervous ticks?

Karmakanix@Sin-Labs http://slurl.com/secondlife/Circe/170/197/504
Karmakanix on SLX http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=61062
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
08-25-2009 16:48
reference one function, store your answers as a series of bitwise arguments, that gives you 32 levels of if testing, with recorded answers to differentiate, then each new level of question will generate a new level of decisions (and please use a binary tree, to parse it all, for your own sake)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Prano Quan
Registered User
Join date: 15 Aug 2008
Posts: 29
08-26-2009 05:17
From: Kelli May
Accurate as that info is, I suspect its not all that helpful to the OP.

By the looks of it, he needs to check if previous inputs have been received, based on the results of a Listen event. So after receiving the first Listen message, he can then wait for a second (and maybe a third, fourth, nth).

At the time the program gets the nth message, the value of the first will not be available for comparison unless it's been stored or a flag set.


edit: should have left this for the scripting forum.



Spot on, this is the one I'm looking for, I'll be practicing the code. Thanks heaps Kelli! I'll keep this posted!
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
08-26-2009 05:36
From: Kelli May
Accurate as that info is, I suspect its not all that helpful to the OP.
Good job of reading between the lines to make sense out of the question.
Prano Quan
Registered User
Join date: 15 Aug 2008
Posts: 29
08-28-2009 17:11
Hi all,

I've got several questions... Ok, this might look tedious, but I promise you, the codes are simple to understand and I'm doing my best to make you understand so you can help me :)

Firstly, how do you set flags? Like what Killie has mentioned earlier...
Secondly, I can predict there are going to be in-depth levels which the user will get up to in order to reach the state so, simply said... will this work? --> EXAMPLE: if(message == "plugged" && second_input_flag && third_input_flag && fourth_input_flag ... and maybe about 3 more???) Will this work?
Third, if I want to display the data which the user has inserted, can I do the following?
EXAMPLE: User is in the last state (in this eg, we'll take 3 levels)

//First Stage---------------------------------------------------------------------
if(message == "plugged";)
{
first_input_flag //I still don't know how to initiate a first_input_flag
llSay (0, "Your TV is plugged.";)
}
else
{
llSay (0, " Hang on, you haven't inserted the correct command or you're not in the right stage yet.";)
}
//Second Stage----------------------------------------------------------------
if(message == "switched on" && first_input_flag)
{
second_input_flag
llSay (0, "Well done, so you've already plugged and switched on your TV! Let's configure it next.";)
}
else
{
llSay (0, " Hang on, you haven't inserted the correct command or you're not in the right stage yet.";)
}
//Third Stage------------------------------------------------------------------
if(message == "configuration terminal" && second_input_flag)
{
third_input_flag
llSay (0, "Ok, you are now in configuration mode, please type in XXXXX to config.";)
}
else
{
llSay (0, " Hang on, you haven't inserted the correct command or you're not in the right stage yet.";)
}

//My 3rd question-----------------------------------------------------
if(message == "show version";)
{
llSay (0, "The following data are the version of TV you have and the configuration you've made: \n";)
llSay (0, "Type: " <--- This is where I get confused, i can simply type-in: "Type: Toshiba/SONY, etc..." but I want it to display whatever the user has inserted, how do I do that?

Therefore, when user inputs "show version", it will whisper/say.... whatever parameters they have introduced, of course there will be restrictions like some inputs MUST be integers, or strings.. If you don't get what I mean... EXAMPLE:
Type: (this input must be a mix between words and numbers, maybe a string will do) Toshiba X31512
2-Quad-Processor: (This input must be simply numbers => integer) 4

That's what I mean...

Thank you all for your time and help, I really appreciate all inputs.
Regards,
Prano
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
08-29-2009 03:15
I suggest when talking code it's better to post in scripting tips... you'll get faster and more indepth replies
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -