If Else Example

Written by Kitsune
// Bromley College
// Linden Script Exhibition
 
// Code for poster 16;
 
// You will notice that this program contains two states default and new. It was necessary to introduce states in this example in order to prevent the poster listening continuously and responding to all events on channel 0. Before introducing states the else condition was even "replying" to the chat messages produced when posters 17 and 18 were touched! ;
 
default
{
    touch_start(integer total_number)
    {
        llSay(0, "What is the number of this              poster? Please reply using chat.");
        state new;
    }
}
 
state new
{
    state_entry()
    {
       llListen(0,"",NULL_KEY, "");
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if(message=="16")
        {
            llSay(0,"Well done your answer is correct");
        }
        else
        {
        llWhisper(0,"Sorry wrong answer, please click on this poster to try again");
        }
        state default;
    }
}
 
// End of code;