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-31-2009 00:59
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?
Secondly, there are going to be a number of 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---------------------------------------------------------------------
//Listen to user input keystroke...

listen(integer channel, string name, key id, string message)
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, PROVIDED they have passed through 1st 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, PROVIDED they have completed 2nd 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..." which is unchangeable data "FIXED" but I want it to display whatever the user has inserted (which is user-variable), 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
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
08-31-2009 01:43
integer red_flag = 1;
integer green_flag = 2;
integer blue_flag = 4;
integer yellow_flag = 8; //double up for each subsequent flag, the powers of 2 set only a single bit

integer flags = 0;

//set flag...
flags = flags | red_flag;

//reset flag...
flags = flags & ~red_flag;

//test flag...
if (flags & red_flag)
{
//etc...
}

//test several flags..
if ((flags & red_flag) && (flags & blue_flag))
{
//etc...
}

Note the distinction between the logical comparator "&&" and the bitwise boolean operator "&", ditto for "||" and "|". And note that "!" is the logical NOT, while "~" is the bitwise NOT.

string red_flag_is_flying_here= "We'll keep the red flag flying here.";
string oh_no_it_isnt = "We're not having any of that stuff here, matey.";

string result = "Current status is: ";

if (flags & red_flag)
{
result += red_flag_is_flying_here;
}
else
{
result += oh_no_it_isnt;
}
llOwnerSay (result);
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
08-31-2009 02:11
If you're looking for a simple linear progression of events I'd go for something more like this:

CODE

integer step;
integer action;
list actions = ["run", "trip", "fall", "scream"];

default
{
state_entry()
{
llListen(1, "", llGetOwner(), "");
}

listen(integer channel, string name, key id, string message)
{
action = llListFindList(actions, [message]);

if (message == "reset")
{
llOwnerSay("Okay, starting from the beginning.");
step = 0;
}
else if (action < 0) llOwnerSay("I think you're just making this up.");
else if (action != step) llOwnerSay("I reject action: "
+ message
+ ", I was expecting: "
+ llList2String(actions, step));
else
{
llOwnerSay("I accept action: " + message);
step += 1;
}
}
}

With lots of flags you're going to drown in: (this & other) && that, kind of stuff.
_____________________
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
08-31-2009 02:47
Of course, there is the simpler method...

integer red_flag = FALSE;
integer blue_flag = FALSE;

//set
red_flag = TRUE;

//reset
red_flag = FALSE;

//test
if (red_flag && blue_flag)
Prano Quan
Registered User
Join date: 15 Aug 2008
Posts: 29
Beautiful
08-31-2009 18:08
Guys, this is beautiful, thank you very much for all your help, I truly appreciate it. Will test out the codes, Will post how I do...

Cheers ya'll.