Panel

Linden Labs

Second Life ® y Linden Lab ® are registered trademarks from Linden Research, Inc. KodigoStyle is not affiliated or sponsored by Linden Reseach.

Tutorial


Hello world! script steep-by-steep. 
    • Get an API code (do it by adquiring the API kit or using an in-world terminal).
    • Drag and drop the API main script in root-prim of the object you want to use.
    • Create a new script and copy-paste in the script-top this code.
    • All done! You can now start developing with the API!
    • To start with your first script, enable the DEBUG option including this code in the main state_entry:
api_set_options([
            "DEBUG", "ON",
            "MSG_CHANNEL", "2000"
        ]);

See the api_set_options documentation.

    • In the state_entry event, use the api_set_code function to specify yor API code.
api_set_code("YOUR API CODE HERE");

    • Lets store our first value! Inside the touch_start event...
We are going to save the "Hello World!" string in a table named 'demoScript'...

api_storage("ADD", "demoScript", "Hello World!", "", "");

... and give feedback to the avatar.

llInstantMessage(llDetectedKey(0), "Data submited!");
    • Save and close your script and then click in the object.
    • Create a new object, drag and drop inside it the API script and create a new script with this code:
    state_entry(){
        api_set_code("YOUR API CODE HERE");
    }
    • In the touch_start event, we are going to call to the data storage system to get all the values in the 'demoScript' table. Remember to set blank the rest of the parameters to don`t filter the query.
api_storage("GET", "demoScript", "", "", "");
    • The API will give us the results via a link_message message. Lets create an event for this:
link_message(integer _sender_num, integer _num, string _str, key _id){
    ...
}

    • The default link_message channel used is 2000. We have to filter other channels (or ignore it)

if(_num!=2000){return;}

    • The API will give us the values on # separated values. Create a list to store each response. This is a example of the API response:
RESPONSE#demoScript#Hello World!##
RESPONSE#demoScript#Hello World!##
RESPONSE#END

    • As you can see, there is also a response that identifies the end of the response. We havee to ignore it too.
    • Create the list and get the first and second values:
list params = llParseString2List(_str, ["#"], []);
string com1 = llList2String(params,0);
string com2 = llList2String(params,1);
    • Identify in the message is a storage system call response, ignore the end delimiter and print the call values.

if(com1=="RESPONSE"){
    integer i;
           
    if(com2=="END")
        return; 
            
    for(i=1;i<llGetListLength(params);i++)
        llInstantMessage(llGetOwner(), (string)(i-1) + " value = " +                      
        llList2String(params,i));        

  Sign in   Recent Site Activity   Terms   Report Abuse   Print page  |  Powered by Google Sites