Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Operator question

tucor Capalini
Registered User
Join date: 18 Jun 2007
Posts: 44
05-01-2008 18:47
This comes from the llMoveToTarget example in the LSL Wikki.

pos+=offset;

what is "+="?
Laurence Corleone
Registered User
Join date: 12 Oct 2006
Posts: 126
05-01-2008 18:54
That means offset is added to pos and pos is no longer just pos so if you called pos earlier in the script it's value would be pos but after pos+=offset it's value would be (pos + offset) and would be able to be called by still just calling pos.
_____________________
There are no stupid questions, just stupid people.
tucor Capalini
Registered User
Join date: 18 Jun 2007
Posts: 44
05-01-2008 18:55
Thank you!
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
05-01-2008 19:47
pos += offset

means the same thing as:

pos = pos + offset

(interesting to note that all the following mean the same thing)

a = a + 1
a += 1
a++

Another handy trick for decoding "advanced scripts", both of these mean the same thing as well

if (value == TRUE)
if (value)

Scripter shorthand can be frustrating for beginners.
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-01-2008 20:12
and while we are at it:

if(value == FALSE)

or

if(value != TRUE)

both mean:

if(!value)

But these are all easy ones and you don't have to worry. The only time you have to start getting scared is when you can look at one of Strife's scripts and it makes sense ;)
_____________________
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
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
05-01-2008 20:44
/me chimes in, since we're giving scripty tips.

Sometimes you see people who write this...

if (42 == x)

...instead of...

if (x == 42)

Although they both work out to the same thing, the first way is actually a 'safer' way to write code.

The reason is that if you typo'ed '=' by mistake instead of '==' the first way would not compile and the 2nd way would happily compile but very likely not do what you expected it to.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
05-01-2008 22:28
Winter you have confused ++a with a++

a++ is not a synonym for a += 1 or a = a + 1
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
05-02-2008 01:37
From: Sindy Tsure
/me chimes in, since we're giving scripty tips.

Sometimes you see people who write this...

if (42 == x)

...instead of...

if (x == 42)

Although they both work out to the same thing, the first way is actually a 'safer' way to write code.

The reason is that if you typo'ed '=' by mistake instead of '==' the first way would not compile and the 2nd way would happily compile but very likely not do what you expected it to.



For starters, if (x = 42) will compile, it just won't work properly (I think it always returns true). Secondly, what's 'safer' about 42 == x over x == 42 ?? Define 'safer'.
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
05-02-2008 03:42
and my personal favorate

if(~expression)

returns false if the expression returns -1 and -1 if the expression returns 0 so

if(~llSubStringIndex(string,val))

will be TRUE if string contains val even if it is the first ellement of the string, which would normaly return 0, the index, which in LSL is FALSE, becouse LSL recognises any non zero value as TRUE.
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
05-02-2008 03:52
From: Johan Laurasia
For starters, if (x = 42) will compile, it just won't work properly (I think it always returns true). Secondly, what's 'safer' about 42 == x over x == 42 ?? Define 'safer'.


It will compile yes, but it will also assign the value 42 to the variable x, so debugging would become a nightmare, safer in this context is that if you get in to the habit of using the 42 == x format and you accidentally enter it as 42 = x, the compiler will generate an error rather than compiling and compounding your error.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-02-2008 04:02
From: Strife Onizuka
Winter you have confused ++a with a++

a++ is not a synonym for a += 1 or a = a + 1

Sure it is, I use it all the time. a++ increments a by one.
CODE
default {
touch_start(integer n) {
integer a = 33;
a++;
llOwnerSay((string)a);
}
}

returns:
temp2: 34

OMG I have to go put a big circle on the calendar today.

5/2/08 "Strife got one wrong!" LOL
_____________________
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
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-02-2008 04:07
ah nearly forgot this one which is indespensible:

value = !value

If value is TRUE, it changes to to FALSE and if value is FALSE, it becomes TRUE.
_____________________
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
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
05-02-2008 04:41
From: Jesse Barnett
Sure it is, I use it all the time. a++ increments a by one.
CODE
default {
touch_start(integer n) {
integer a = 33;
a++;
llOwnerSay((string)a);
}
}

returns:
temp2: 34

OMG I have to go put a big circle on the calendar today.

5/2/08 "Strife got one wrong!" LOL

Don't be so sure
++x is incremented before use and x++ is incremented after!

integer x=8;
llOwnerSay((string)(++x)); // say 9
x = 8;
llOwnerSay((string)(x++)); // say 8
llOwnerSay((string)x; // say 9

(I have not tested this)
_____________________
From Studio Dora
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
05-02-2008 04:51
if(calender == marked)llTipex(calender);
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-02-2008 04:55
From: Dora Gustafson
Don't be so sure
++x is incremented before use and x++ is incremented after!

integer x=8;
llOwnerSay((string)(++x)); // say 9
llOwnerSay((string)(x++)); // say 8

(I have not tested this)

Now think about this a min.

llOwnerSay((string)(x++)); // say 8
is calling x before it is incremented but it is STILL incremented and if you call
llOwnerSay((string)x) afterwards, it will return 9

CODE
default {
touch_start(integer n) {
integer a = 33;
llOwnerSay((string)a++);
llOwnerSay((string)a);
}
}

returns:
new: 33
new: 34

Per the wiki:
"variable++ | Arithmetic post-increment | variable | variable is set to variable + 1
++variable | Arithmetic pre-increment | variable + 1 | variable is set to variable + 1 "
_____________________
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
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
05-02-2008 05:04
From: Jesse Barnett
Now think about this a min.

llOwnerSay((string)(x++)); // say 8
is calling x before it is incremented but it is STILL incremented and if you call
llOwnerSay((string)x) it will return 9

but if x = 8
llOwnerSay((string)(x++));
is still not the same as
llOwnerSay((string)(x += 1));
or
llOwnerSay((string)(x = x + 1));

the results are 8, 9 and 9 respectivly
where as
llOwnerSay((string)(++x));
will return 9 which i think was Strifes point
From: someone
Winter you have confused ++a with a++

Many a night has been spent debugging code due to a simple error in execution order.
so in this case I think that post increment is not equivalent to increment
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-02-2008 05:24
From: Very Keynes
but if x = 8
llOwnerSay((string)(x++));
is still not the same as
llOwnerSay((string)(x += 1));
or
llOwnerSay((string)(x = x + 1));

the results are 8, 9 and 9 respectivly
where as
llOwnerSay((string)(++x));
will return 9 which i think was Strifes point

Not really:

CODE
default {
touch_start(integer n) {
integer a = 1;
integer b = 33 + a++;
a += b;
llOwnerSay((string)a);
}
}


That is adding 33 + 1 + 1 and returns correctly 36
BUT if you change that line to :
integer b = 33 + ++a;
You are adding 33 + 1 + 1 + 1 and returns 37
_____________________
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
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-02-2008 05:31
From: Very Keynes
but if x = 8
llOwnerSay((string)(x++));
is still not the same as
llOwnerSay((string)(x += 1));
or
llOwnerSay((string)(x = x + 1));

the results are 8, 9 and 9 respectivly
where as
llOwnerSay((string)(++x));
will return 9 which i think was Strifes point

Many a night has been spent debugging code due to a simple error in execution order.
so in this case I think that post increment is not equivalent to increment

I love these little brain exercises in the morning!

OK back to Strife's post:

"a++ is not a synonym for a += 1 or a = a + 1"

It is and if anything ++a is not synonymous to a + 1, instead it is the same as:

a = 1 + a
_____________________
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
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-02-2008 05:41
But I do finally see the light, although may not agree with the symantics :rolleyes:

I would imagine that Winter has always doen like I have and declared:

a = whatever;
a++;
Use "a" wherever.

But doing it the other way means you can skip declaring
a++; 1st and go right to incrementing in a function instead:

b = c * ++a;

But if you do have to declare it for use in multiple places then :

a++;
++a;

both increment by one
_____________________
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
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
05-02-2008 06:19
++a;
a++;

if used as the above example shows are the same.

Though if used in formulas,

++a will increment the value first, THEN evaluate the formula whereas
a++ will evaluate the formula and THEN increment a by 1.

That is the one and only major difference between these notations that one needs to be aware of.
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
05-02-2008 14:54
That and ++a is a little faster than a++..