Sloodle wait for configuration

From SLIS Second Life Wiki

Jump to: navigation, search

Contents

[edit] Introduction

This is a fragment from the Sloodle LSL Library, meaning that you must copy-and-paste it into your own LSL scripts in order to use it. You may also need to customize it to suit your own needs.

The fragment is an LSL state designed for objects which need to receive some kind of configuration before being usable. When transferred into this state, the script will do nothing but recevie link messages, and send them on to an appropriate handling function which you must also define in your code (see sloodle_handle_command). Once configuration is complete, the state should transfer control to an appropriate subsequent state (such as 'default') or similar.


[edit] Channel Numbering

Note: according to the Sloodle conventions, all data transfer/communication in-world should use the standard channels (see Sloodle channels). For data transfer between objects, such as configuration commands, this should be SLOODLE_CHANNEL_OBJECT_DIALOG.


[edit] After Configuration

Your script should be configured to detect when all expected configuration data has arrived. When it has, the state is changed using the LSL "state" command. It is best not to do this within a function, so it is recommended that your sloodle_handle_command function returns TRUE (that is, integer 1) if the script is fully configured, or FALSE (that is, integer 0) if not. The "link_message" event in this state can then check the return value and respond appropriately.

It is intended that some kind of "EOF" (end-of-file) command will be implemented, so that when all available configuration data has been sent to your object, the last command will be "EOF". When received, your sloodle_handle_command function should check if all required data has been specified, and either continue waiting or issue an error if not. The purpose of the EOF command is to allow additional optional data to be specified, so that even after all required data has arrived, your script will continue to wait in case anything optional is also specified. However, this should only affect the sloodle_handle_command function.


[edit] Example Code

Here is an example of the state:


// It is important to declare the correct channel number
integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;


// Insert the sloodle_debug function here if you want to use it
//...


state sloodle_wait_for_configuration
{
    state_entry()
    {
        // This is optional, and you must define the sloodle_debug function if you want to use it:
        sloodle_debug("Waiting for configuration commands.");
    }
    
    link_message( integer sender_num, integer num, string str, key id)
    {
        // Check that the message is on the correct channel
        if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
            // Send the command, and check if configuration is complete
            if (sloodle_handle_command(str) == TRUE) {
                // Configuration is complete. Move on...
                sloodle_debug("Configuration complete.");
                state default; // <-- change this state if you want to use something else
                return;
            }
        }
    }
}


This page is part of the Sloodle documentation
SloodleDocs Home | User Documentation | Administrator Documentation | Developer Documentation | Sloodle Wiki Home
Personal tools