PASTE NAVIGATION MENU CODE

Wednesday 27 June 2012

Task 2: Responding to Commands

| | with 0 comments |
In this section, an object will be built which responds to user commands. For this simple example, we shall start building a kiosk. The stool created previously will be placed in front of a terminal resembling an arcade machine. For the purposes of this test, a large button will then be placed on the kiosk which sends an email when it is touched. 

The kiosk was built by placing a prism prim onto an elongated cube prim. The button was then created by placing a smaller cube on top of the larger one.



The action desired is for the "button" to send an e-mail when it is touched. Using LSL, the user will be asked for the e-mail address to use to send the e-mail. An e-mail will then be sent.



All interaction with the user happens via the chat window. To accomplish this task, the following LSL script was added to the button.


integer listen_handle;

default{
    state_entry(){   
        listen_handle = llListen(0, "", llGetOwner(), "");
    }
    touch_start(integer num_detected){
        llOwnerSay("Please type in an e-mail address");
    }
    listen( integer channel, string name, key id, string message ){  
        llOwnerSay("An e-mail has been sent to " + message);
        llEmail( message, "E-mail from Kiosk", "Hi there!");
        llListenRemove(listen_handle);
    }
    on_rez(integer param){   
        llResetScript();
    }
    changed(integer mask){   
        if(mask & CHANGED_OWNER){
            llResetScript();
        }
    }
}
When the user touches the button, a message is sent to the owner (i.e. the user touching the button) instructing them to type in their e-mail address. In the state_entry() state (the initial state of the button) a listener is registered which will "listen" for text which the user will type in the chat window. When text is typed, an e-mail will be sent to the address typed in by the user. This is done using the llEmail function. The user is also informed that the message has been sent. When received, the message is as follows:


As can be seen, the message "Hi there!" which is specified in the script is received in the main content. Second Life also sends via e-mail the name of the object, the region where the object resides and the current local position. When the e-mail has been sent the script resets itself and is hence ready to send another e-mail. The script is also reset if another user touches the button - creating separate instances for all the users currently using the object. This makes it possible for several players to be using the object concurrently. To create the script, the "New Script" button was used from the content pane of the build window. This brings up a code editor where script can be typed. The script is compiled on saving, and any syntax errors are displayed in the window.


The editor features code coloring, but no completion or in-line debugging. Luckily, the Second Life wiki (Link) as well as Internet searches provide a wealth of documentation regarding the functions of LSL, as well as ready-made code to use freely or to purchase. The Second Life marketplace (Link) is the primary store for all things Second Life, including objects, clothing and scripts.

Post a Comment

Please enter your comments here..

0 comments: