Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Behaviour and processing of conditionals

Luke Mommsen
Registered User
Join date: 9 Oct 2005
Posts: 33
10-23-2009 06:11
Okay, so here's the deal, in most languages, and previously in LSL, when you have a conditional statement such as, if (A && B) then ... It's my understanding that first the A is processed, and if found TRUE, then B is processed. But should A be FALSE, then B is simply forgotten and skipped over.

Now I know that this is how LSL used to treat this kind of code, because I've been using a form of PointInPoly that requires this behaviour and it worked fine until recently. Now you wouldn't believe how badly I've been racking my brain trying to figure out why the script was now giving me a math error.

Apparently LSL now processes both conditions even if the first is false. Easily fixed now I know, simply nest another if statement. But still, why has this behaviour changed? Surely I'm not the only one that's noticed this?
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
10-23-2009 07:21
I would never rely on a thing like that.
It is not documented anywhere and the code itself tells nothing about how the statement is interpreted.
_____________________
From Studio Dora
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-23-2009 07:43
I do not know about the order of processing but it still only works if both are TRUE

CODE

integer A = 1;
integer B = 1;

default {
touch_start(integer n) {
if(A&&B){
llOwnerSay("both are true");
}
}
}


What is not working and do you have a code fragment to demo it?
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
10-23-2009 08:21
From: Luke Mommsen
Okay, so here's the deal, in most languages, and previously in LSL, when you have a conditional statement such as, if (A && B) then ... It's my understanding that first the A is processed, and if found TRUE, then B is processed. But should A be FALSE, then B is simply forgotten and skipped over.

Now I know that this is how LSL used to treat this kind of code, because I've been using a form of PointInPoly that requires this behaviour and it worked fine until recently. Now you wouldn't believe how badly I've been racking my brain trying to figure out why the script was now giving me a math error.

Apparently LSL now processes both conditions even if the first is false. Easily fixed now I know, simply nest another if statement. But still, why has this behaviour changed? Surely I'm not the only one that's noticed this?
This is the way LSL behaves, certainly -- processing B whether or not A is true. But I don't think the change is recent; it's certainly been around since I started learning scripting, and it seems first to have been noted in the lsl wiki back in January 2007: http://lslwiki.net/lslwiki/wakka.php?wakka=IfElse/show&time=2007-01-15+22:40:37 :
From: someone
In a short-circuited language if the left-hand side of a logical AND (&&;) is FALSE the right-hand side is never tested since the entire test would always return a FALSE output no matter what the value of the right-hand side. Since LSL is not short circuited, both the left and the right-hand sides are tested all the time.
I note this not out of historical interest but because it suggests you may be misdiagnosing the reason for your math error.
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
10-23-2009 08:25
CODE

integer FA( integer a)
{
if ( a ) llOwnerSay("FA is TRUE");
else llOwnerSay("FA is FALSE");
return a;
}

integer FB( integer b)
{
if ( b ) llOwnerSay("FB is TRUE");
else llOwnerSay("FB is FALSE");
return b;
}

both( integer i)
{
if ( i ) llOwnerSay("both are TRUE");
else llOwnerSay("both are not TRUE\n");
}

default
{
touch_start(integer n)
{
both(FA(0) && FB(0));
both(FA(0) && FB(1));
both(FA(1) && FB(0));
both(FA(1) && FB(1));
}
}
When executed this test script gives following:
LSL Logic: FB is FALSE
LSL Logic: FA is FALSE
LSL Logic: both are not TRUE

LSL Logic: FB is TRUE
LSL Logic: FA is FALSE
LSL Logic: both are not TRUE

LSL Logic: FB is FALSE
LSL Logic: FA is TRUE
LSL Logic: both are not TRUE

LSL Logic: FB is TRUE
LSL Logic: FA is TRUE
LSL Logic: both are TRUE

This tells me that both A and B are executed no matter their logic values.
Still I would never rely on one or the other assumption.

The result is the same if compiled in MONO or not.
_____________________
From Studio Dora
Luke Mommsen
Registered User
Join date: 9 Oct 2005
Posts: 33
10-23-2009 16:30
Wow, this is a huge and awesome help guys. I seriously don't know how I wasn't running into this issue more previously. All fixed now though! *grins*

Basically I was basing some code around the PNPoly idea.
http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

As I said though, it really had seemed to work previously. Hope all goes well from here on out! Thanks again!