Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Bunch'a constants.
- string A_THING = "thing"; // Name of a prim you expect to find in the linkset.
- string SOMETHING_ELSE = "another"; // Another one.
- string THIRD_THING = "a third"; // And another.
- vector WHITE = <1.0, 1.0, 1.0>; // Always remember to type the .0 where LSL expects a float.
- vector RED = <1.0, 0.0, 0.0>; // Otherwise, the script has to do extra work.
- // Note that if we were using the LSL preprocessor, constants can be done with #define instead.
- //
- // [ Also note that unless these strings are four characters or less,
- // it does waste some memory to do it this way.
- // This is not a concern unless you're an LSL guru. ]
- //
- // Integer, float, and vector constants should all be done as #defines.
- // Our global variables, very important.
- integer thing; integer something; integer third;
- integer setup_linkset() {
- llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_TEXT, "", WHITE, 0.0]);
- // Now we look for the prims we require.
- // Setting these to an invalid value so we can tell if we couldn't find something.
- thing = -1; something = -1; third = -1;
- integer i; integer guard = llGetNumberOfPrims();
- string name;
- for(i = 1; i <= guard; ++i) {
- // Prims in a linked object are numbered from 1 to the number of prims, inclusive.
- name = llGetLinkName(i);
- if (name == A_THING) { thing = i; }
- else if (name == SOMETHING_ELSE) { something = i; }
- else if (name == THIRD_THING) { third = i; }
- }
- if (something < 0) { // We've decided that we can't go on if we don't find this prim.
- llSetText("Bootup failure.", RED, 1.0); // Report failure to the user...
- return FALSE; // ... and to the rest of the script.
- }
- return TRUE; // Report success.
- }
- integer last_prims; // The number of prims we had last time we booted up.
- // Make functions from code snippets you find yourself copy/pasting.
- prim_text(integer lnum, string text) {
- llSetLinkPrimitiveParamsFast(thing, [PRIM_TEXT, text, WHITE, 1.0]);
- }
- default { state_entry() {
- last_prims = llGetNumberOfPrims();
- if (!setup_linkset()) { state idle; } // Try to setup, and go idle if we fail.
- state active;
- } }
- // If we're here, we failed to find what we need.
- state idle { touch_end(integer n) { if (llDetectedKey(0) == llGetOwner()) {
- state default; // Only change states on touch inside a touch_end... bad things will happen otherwise.
- } } }
- // In a real script, this is where normal operation would happen.
- state active {
- state_entry() { // Do something amazing!
- prim_text(thing, "a thing");
- prim_text(something, "the something");
- prim_text(third, "third thing");
- } // Okay, maybe not that amazing. But you get the idea.
- changed(integer change) { if (change & CHANGED_LINK) {
- integer prims = llGetNumberOfPrims();
- if (prims == last_prims) { return; } // No change, do nothing.
- state default; // If we got here, it changed. Reconfigure!
- } }
- touch_start(integer n) {
- integer lnum = llDetectedLinkNumber(0);
- // The 0 means we're asking about the first touch, if there were a bunch at the same time.
- // [ This is how all the llDetected* functions work. ]
- // Figure out what prim was touched, and do something appropriate.
- if (lnum == thing) {
- llSay(0, "get'cha handz off mah primz!");
- llSleep(1.0);
- llSay(0, "... sorry.");
- } else if (lnum == something) {
- llSay(0, "the all-important something!");
- }
- else if (lnum == third) { llOwnerSay("yo."); }
- else { llOwnerSay("."); }
- }
- // Something you could do instead.
- //touch_end(integer n) { if (llDetectedKey(0) == llGetOwner()) { llResetScript(); } }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement