Evaluation Order

In short, the evaluation order in LSL goes:

So take an example:

integer x=0;
llSay(x++, (string)(a(x++) + b(++x)));

where a and b are defined functions in the script.

  1. Left-to-right in parameters: The first x++ will be evaluated first. It's postfix, so the value is changed after it is used. I.e. the script stacks a zero for channel in the llSay function…
  2. …and increments x to 1.
  3. Next parameter is in itself an expression. That's right-to-left, so b() is up first.
  4. b takes a parameter, which is the prefixed ++x. So x is increased to 2 before being sent to the function…
  5. …and b is called, stacking its result.
  6. Function a() is then evaluated. x++ is postfix, so x is changed after it is used, i.e. function a is called with the current value 2, stacking the result…
  7. …and x is increased to 3.
  8. The stacked results from a and b are added, and llSay fires, speaking out on the previous stacked channel 0.

And x is by now 3, corresponding to the 3 increases it received during the command.