Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

*PROBLEM* Scripting with FLAGS

Prano Quan
Registered User
Join date: 15 Aug 2008
Posts: 29
09-22-2009 20:01
Hi all, I have a problem with scripting with flags. The problem is stopping flags or .. separating from one flag to another. I will explain, please note that the scenario has been edited to make things a LOT simpler. Here is a scenario which is very similar to my scripting issue:

-------------------------beginning of code----------------------------
Flags have all been set to false.
llListen is running.

//Stage 1

if ( message == "Object 1 POWER ON";)
{
llSay ( Yes yes, object 1 is now ON)
flag1 = TRUE;
}

//Stage 2

if(message == "object 2 POWER ON";)
{
llSay( Object 2 is now ON)
flag2 = TRUE;
}

//Stage3

if(message == "Can Object 1 talk to Object 2?" && flag1)
{
llSay(no, object 2 needs to be powered up first.)
}

//Stage 4

if (message == "Can Object 1 now talk to object 2?" && flag2)
{
llSay( Yes, they both can talk to each other because now they're both ON";)
}

-------------------------end of code----------------------------

The problem I have is when the user successfully go through Stage 4, Stage 3 is also carried out automatically (they are assuming flag 2 is already achieved, they will post everything from then until the flag on the current input)

I'm gonna give a run through if some people still don't understand:
User types all the necessary inputs for Stage 1 and Stage 2 (in order to get to Stage 4). When User finally types Stage 4 "Can Object 1 now talk to object 2?", we expect the program to run and say "Yes, they can... etc". But instead, it ALSO posts Stage 3 which is "No, they can't because both objects have to be ON". Which is NOT right.

How do I solve this problem? Thank you for your time
Klug Kuhn
Registered User
Join date: 7 Sep 2007
Posts: 126
09-22-2009 20:36
You may need to separate the condition from

if(message == "Can Object 1 talk to Object 2?" && flag1)

into something like this just to make sure:

if ( (message == "Can Object 1 talk to Object 2?";) && (flag1) )


Also should try else-if when you know there'll be only 1 outcome, e.g.

if ( (message == "Can Object 1 talk to Object 2?";) && (flag1) ) // Stage 3
{
llSay(no, object 2 needs to be powered up first.)
}
else if ( (message == "Can Object 1 now talk to object 2?";) && (flag2) ) // Stage 4
{
llSay( Yes, they both can talk to each other because now they're both ON";)
}

This will not only provide 1 outcome but also increase the script efficiency. :)
Prano Quan
Registered User
Join date: 15 Aug 2008
Posts: 29
09-22-2009 21:11
Hi Klug,

Placing brackets into message and flags within (message && flag) doesn't change a thing. In other words, it doesn't make a difference.

HOWEVER, I have good news!!! doing an (if else) statement) works!!! I don't get spammed from previous flags anymore! Thanks Klug, will post if I face further difficulties with flags.
Klug Kuhn
Registered User
Join date: 7 Sep 2007
Posts: 126
09-22-2009 22:27
You're welcome~ :)