Jump to content

If statement help!


Tomkinson
 Share

You are about to reply to a thread that has been inactive for 4172 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I am having some trouble with my code. 

On my island is a clock that tells the time in GMT, it also uses llRegionSay to broadcast the raw seconds since midnight. I've got a box that listens for the time and at a certain trigger time turns from black to red. I want to be able to set that trigger without having to go into the script to change it so I am trying to get it to listen to another channel to set that time. For some reason though it's not working and I can't work out why. It seems to store the number I say to it on channel 3 and will set itself to black when I try and change the colour. When the number comes up that it's waiting for though it does nothing.  Can anyone help?

 

string lecture;

default
{
    state_entry()
    {
        llSay(0, "Hello, Avatar!");
        llListen(2, "", "", "");
        llListen(3, "", "", "");
        lecture = "1";
    }

    touch_start(integer total_number)
    {
        llSay(0, lecture);
    }
    
    listen(integer channel, string name, key id, string message)
    {
        if(channel == 2)
        {
            if(message == lecture)
            {
                llSetColor(<1.0, 0.0, 0.0>, ALL_SIDES);
                llSleep(60.0);
            }
            else
            {
                llSetColor(<0.0, 0.0, 0.0>, ALL_SIDES);
            }
        }
        
            if(channel == 3)
            {
                lecture = message;
            }
            else
            {
            }
        
    }
}

 

Link to comment
Share on other sites

What you are saying is that if you pass "doit" for instance on channel 3, then a subsequent message of "doit" on channel 2 will not set the color to red?  The only thing I can think if is that you are sending the message to channel 3 before the 60 second llSleep after sending a message to channel 3 has timed out.

Link to comment
Share on other sites

You have a few of things going on.  First, you are sending the message "lecture" by triggering a touch event and then expecting to hear the result in a listen event in the same script.  That's not ever going to work.   A script can't listen to itself except in the particular case of a dialog or textbox. In this case, it's really not going to work because you are sending the message on the public chat channel (0) and you don't have a listener open on that channel at all.

Second, you are sending "lecture" as a string and seem to be intending to use it as an integer.  It can't be both at the same time.  At some point you have to write (integer) lecture to convert it. 

Third, xtc4u is right: llSleep is blocking your script from hearing anything while it's active.  It does exactly what it says.  The entire script goes to sleep, unable to listen, respond to any stimuli, or do anything.  Miss that window and it will never hear a thing.

Link to comment
Share on other sites

Brilliant, fixed. 

The time was being shouted with 6 decimal places on the end of it and I wasn't listening for the decimal places. So it differentiated between 60300.000000 and 60300 for instance. Easy fix. Can't believe I missed it. :matte-motes-smile:

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4172 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...