jump target;
| label | target | Name of a label inside the same function or event scope. |
| label | target | A label that can be jumped to, if the jump is in the same scope or child scope. It isn't possible to jump between scopes (such as between functions, events or states). |
integer a = 5;
jump over;
@in;
a = 6;
@over;
llOwnerSay((string)a);
if(a < 6)
jump in;
//script will say 5 and then 6
integer getLinkWithName(string name)
{
integer i = llGetLinkNumber() != 0; // Start at zero (single prim) or 1 (two or more prims)
integer x = llGetNumberOfPrims() + i; // [0, 1) or [1, llGetNumberOfPrims()]
for (; i < x; ++i)
{
if (llGetLinkName(i) == name)
jump break; // Found it! Exit loop early with result
}
i = -1; // No prim with that name, return -1.
@break;
return i;
}
More often than not, the rather ugly 'jump' can be avoided, especially in user defined functions, as this version of the above script demonstrates
integer getLinkWithName(string name)
{
integer i = llGetLinkNumber() != 0; // Start at zero (single prim) or 1 (two or more prims)
integer x = llGetNumberOfPrims() + i; // [0, 1) or [1, llGetNumberOfPrims()]
for (; i < x; ++i)
{
if (llGetLinkName(i) == name)
return i; // Found it, return its index
}
return -1; // No prim with that name, return -1.
}
It is generally considered inadvisable to use jumps (commonly know as gotos) where other flow control structures could be used.
| return | ||
| state |
The following function, jumpy, demonstrates the multiple-jump-sites-to-a-single-target bug. It appears this function should result in an infinite loop, and it does when the script is compiled for the Mono VM. However when compiled for LSO VM because of this bug the second jump never happens and the function returns. LL reported they were unwilling to fix this bug as to do so would be a breaking change. This bug was fixed in the newer Mono VM.
jumpy(){
jump next;//first jump
@next;
jump next;//second jump - BUG never gets executed
return;
}