Difference between revisions of "Jump"
Jump to navigation
Jump to search
Line 26: | Line 26: | ||
jump in; | jump in; | ||
//script will say 5 and then 6</lsl> | //script will say 5 and then 6</lsl> | ||
<lsl>integer getLinkWithName(string name) { | |||
integer x = llGetNumberOfPrims(); | |||
integer i = (x > 1); // Start at zero (single prim) or 1 (two or more prims) | |||
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; | |||
}</lsl> | |||
}}{{#vardefine:notes| | }}{{#vardefine:notes| | ||
}}{{#vardefine:caveats| | }}{{#vardefine:caveats| |
Revision as of 14:51, 9 January 2012
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
- The correct title of this article is jump. The initial letter is shown capitalized due to technical restrictions.
jump target;
jump target;• label | target | – | Name of a label inside the same leg of the scope hierarchy tree |
@target;
• 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 or states). |
Caveats
- If multiple jumps are declared for the same target label within scope, then only the first will function as expected, all others will silently fail.
- Labels are scoped at the event and function level, meaning that it is not possible to declare duplicate labels within the same event or function, even if the labels are enclosed in different if-statements, loops etc. Attempting this will result in an unhelpful CIL assembly related error.
Examples
<lsl>integer a = 5; jump over; @in; a = 6; @over; llOwnerSay((string)a); if(a < 6)
jump in;
//script will say 5 and then 6</lsl> <lsl>integer getLinkWithName(string name) {
integer x = llGetNumberOfPrims(); integer i = (x > 1); // Start at zero (single prim) or 1 (two or more prims) 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;
}</lsl>