11.07.2015 Views

Linden Scripting Language Guide - Engineering Center

Linden Scripting Language Guide - Engineering Center

Linden Scripting Language Guide - Engineering Center

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.3. JumpsChapter 4. Flow ControlA jump is used to move the running script to a new point inside of a function or event handler. You cannot jumpinto other functions or event handlers. Usually, you will want to use a jump for in situations where the if..elsestatements would become too cumbersome. For example, you may want to check several preconditions, and exitif any of them are not met.attach_if_ready(vector target_pos){// make sure we have permissioninteger perm = llGetPerm();if(!(perm & PERMISSION_ATTACH)){jump early_exit;}// make sure we’re 10 or less meters awayvector pos = llGetPos()float dist = llVecDist(pos, target_pos);if(dist > 10.0){jump early_exit;}// make sure we’re roughly pointed toward the target.// the calculation of max_cos_theta could be precomputed// as a constant, but is manually computed here to// illustrate the math.float max_cos_theta = llCos(PI / 4.0);vector toward_target = llVecNorm(target_pos - pos);rotation rot = llGetRot();vector fwd = llRot2Fwd(rot);float cos_theta = toward_target * fwd;if(cos_theta > max_cos_theta){jump early_exit;}// at this point, we’ve done all the checks.attach();}@early_exit;4.4. State ChangeState change allow you to move through the lsl virtual machine’s flexible state machine by transitioning yourscript to and from user defined states and the default state. You can define your own script state by placing the15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!