|
|
| (13 intermediate revisions by 2 users not shown) |
| Line 1: |
Line 1: |
| {{LSL Header}} | | {{LSL Header}} |
| | Thinker | Trouble-shooter | Problem-Solver |
| | ---- |
|
| |
|
| | | {{visl |
| | | |name=DoteDote Edison |
| Not a Wiki pro, so using this page to figure out how to format properly.
| | |Greeters= |
| | | |Helpers=* |
| ====Example Scripts for the Examples page once it's formatted:====
| | |Instructors= |
| =====Toggle On/Off via State=====
| | |Mentors=* |
| An example script showing how [[state]] changes can be a useful method to switch between two script modes, in this case, On or Off. When the script first runs, it begins in the '''default''' state and the [[state_entry]] event is executed. When a user interacts with the object by touch, the script switches to the '''on''' state. The '''on''' state executes its state_entry event, then waits for a user touch to trigger a state change back to the '''default''' state.
| | |LSL= |
|
| | |i18n= |
| <pre><lsl>
| | |l10n= |
| // Toggle On-Off via State
| | |SL4B= |
| | | |}} |
| default {
| | {{skills |
| state_entry() {
| | |Builder=* |
| // run this code when entering the default state
| | |Scripter=* |
| // displays red "OFF" as floating text above the prim
| | |}} |
| llSetText("OFF", <1,0,0>, 1.0);
| |
| }
| |
| touch_start(integer num_detected) {
| |
| // when touched, switch to state named 'on'
| |
| state on;
| |
| }
| |
| }
| |
| | |
| state on {
| |
| state_entry() {
| |
| // run this code when entering state 'on'
| |
| // displays green "ON" as floating text above the prim
| |
| llSetText("ON", <0,1,0>, 1.0);
| |
| }
| |
| touch_start(integer num_detected) {
| |
| // when touched, switch to the default state
| |
| state default;
| |
| }
| |
| }
| |
| </lsl></pre>
| |
| ====Email-to-IM Script for the Script Library====
| |
| <pre><lsl>
| |
| // Email-to-IM
| |
| // DoteDote Edison
| |
| | |
| ///////// constants /////////
| |
| // how often to check for new email when owner is online (seconds)
| |
| float fast = 60.0;
| |
| // how often to check owner online status when owner is offline (seconds)
| |
| float slow = 300.0;
| |
| | |
| ////////// globals //////////
| |
| key request;
| |
| key owner;
| |
| integer owner_online;
| |
| | |
| default {
| |
| state_entry() {
| |
| owner = llGetOwner();
| |
| string address = (string)owner + "@lsl.secondlife.com";
| |
| llSetText("Email Server\nOnline", <0.25, 1.0, 0.25>, 1.0);
| |
| llOwnerSay("Now online. The Email-to-IM address for " + llKey2Name(owner) + " is:\n" + address);
| |
| llSetTimerEvent(fast);
| |
| }
| |
| on_rez(integer start_param) {
| |
| llResetScript();
| |
| }
| |
| touch_start(integer num_detect) {
| |
| if (llDetectedKey(0) == owner) state off;
| |
| }
| |
| email(string time, string sender, string subject, string body, integer num_remain) {
| |
| llInstantMessage(owner, "Email Received from: " + sender + " -- " + time);
| |
| llInstantMessage(owner, body);
| |
| if (num_remain > 0) llGetNextEmail("", "");
| |
| }
| |
| dataserver(key query, string data) {
| |
| if (query == request) {
| |
| request = "";
| |
| if (data == "1") {
| |
| owner_online = TRUE;
| |
| llSetTimerEvent(fast);
| |
| }
| |
| else {
| |
| owner_online = FALSE;
| |
| llSetTimerEvent(slow);
| |
| }
| |
| }
| |
| }
| |
| timer() {
| |
| request = llRequestAgentData(owner, DATA_ONLINE);
| |
| if (owner_online) llGetNextEmail("", "");
| |
| }
| |
| state_exit() {
| |
| llSetTimerEvent(0.0);
| |
| llSetText("Email Server\nOffline", <1.0, 0.25, 0.25>, 1.0);
| |
| }
| |
| } | |
| | |
| state off {
| |
| touch_start(integer num_detect) {
| |
| if (llDetectedKey(0) == owner) state default;
| |
| }
| |
| on_rez(integer start_param) {
| |
| llResetScript();
| |
| }
| |
| } | |
| </lsl></pre>
| |
Thinker | Trouble-shooter | Problem-Solver