Jump to content

Prim Listens for chat commands to cause events of different duration


Tirips
 Share

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

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

Recommended Posts

Hi, this is my first post to the forum, I hope I don't do it wrong. 

I have a prim that listens for me to say things in hidden chat channel, and depending on what it hears, it changes prim color for 2.5 seconds, then the prim color resets. My avatar is a robot and I use colored lights for very simple non-verbal communication.  I wrote the script a long time ago and it works fine.

But I'm trying to add a new function. I added an on-off switch my avatar where clicking it triggers a body animation, and the button says "off" into hidden chat. I want the lights to continue changing colors for 2.5 seconds as they always have, UNLESS it hears "off" in which case it turns lights dark indefinitely, until the switch on my neck is clicked again and says "reset" to turn the lights on again. This is the part I'm having trouble with: hearing "off" works and turns the prim color dark grey -- but only for 2.5 seconds. How can I have the "off" function escape the color-reset 2.5 seconds later?

To say it more clearly, I want hearing "off" to turn prim dark grey, indefinitely, until it hears "reset" again from other prim being touched again. 

Here is my marked-up script:

float delay=2.5;
default
{
    state_entry() {
        llListen(89,"", NULL_KEY, "");
    }
    listen(integer channel, string name, key id, string message) 
    {
        if (message == "no")  //hearing "no" turns prim red for 2.5 seconds
        {
            llSetColor(<1,0,0>,ALL_SIDES); 
            llSetTimerEvent(delay);
        }
        if (message == "yes")  //hearing "yes" turns prim green for 2.5 seconds
        {
            llSetColor(<0,1,0>,ALL_SIDES); 
            llSetTimerEvent(delay);
        }
        if (message == "uhm")  //hearing "uhm" turns prim yellow for 2.5 seconds
        {
            llSetColor(<1,1,0>,ALL_SIDES); 
            llSetTimerEvent(delay);
        }
        if (message == "reset")  //hearing "reset" resets color to pink
        {
            llSetColor(<1.0,0.424,0.710>,ALL_SIDES);
        }
        if (message == "off")  // hearing "off" turns prim dark grey -- ideally indefinitely until prim hears "reset" 
        {
            llSetColor(<0.2,0.2,0.2>,ALL_SIDES); 
        }
    }
    timer() 
    {
        llSetColor(<1.0,0.424,0.710>,ALL_SIDES);  //resets color to pink
    }
}

I tried to add an llSetTimer to the if-statement for "Off" (llSetTimerEvent(0.0);) but the prim color resets to pink anyway. 

Thank you for the help, I'm a weak scripter.

Link to comment
Share on other sites

Have the listener do 2 things for "off":

- llSetColor(..);  //for the "off" colors.

- llSetTimerEvent(0.0);   // This will turn "off" the timer.

I see you are already setting a color for "off", maybe you just need to add:

llSetTimerEvent(0.0);

Link to comment
Share on other sites

Hi, thanks for replying. I did try the llSetTimerEvent(0.0); inside the if-statement for "off" but it doesn't seem to do anything. The lights still go dark -- but only for 2.5 seconds. It is as if the timer always picks the biggest number it saw? I don't understand. 

Wait... I think it's working ... why didn't it before??? That's why i made the comment post to begin with LOL.

Link to comment
Share on other sites

llSetTimerEvent(0.0) is the normal way to stop a running timer, so placing that inside the code block for the "off" test should have worked. Why it didn't when you first tried, I can only speculate... Since you said it still reset the color 2.5 seconds after, I would presume that you didn't in fact stop the timer when you ran the "off" code block. Perhaps you placed the llSetTimerEvent(0.0) function in the wrong place without realizing? Or maybe you still were passing the delay variable into it instead of 0.0? Without seeing the failing code in question, it's just me guessing what might have happened.

One additional point:

11 hours ago, Tirips said:

It is as if the timer always picks the biggest number it saw?

A script can only have one active timer running. Calling the llSetTimerEvent function again will override the timer with whatever new value you supply. Doesn't matter if the new value is bigger or smaller, it will always overwrite it and restart the timer countdown. Also, once started, a timer will generally run forever until explicitly stopped (or the script is reset).

In that regard, your timer is actually constantly running and resetting the color back to pink after the first time it hears any of the non "off" or "reset" messages. Even when otherwise appearing to be idle, It's performing unnecessary updates. Granted, this script is very simple and the timer delay long enough that it's not going to cause meaningful impact. But I would recommend you consider adding llSetTimerEvent(0.0) to the timer event to stop the running timer after it performs the regular delayed reset. If anything, I believe it's good practice and it may save you some confusion if you make other changes to the script and aren't expecting the timer to still be silently running.

Edited by Fenix Eldritch
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

@Tirips,

To be specific, this was my suggestion; if you did not put the llSetTimerEvent(0.0) exactly here, that could explain why it did not work:

        if (message == "off")  // hearing "off" turns prim dark grey -- ideally indefinitely until prim hears "reset" 
        {
            llSetColor(<0.2,0.2,0.2>,ALL_SIDES); 
            llSetTimerEvent(0.0); // <<== Add this line here
        }

And, I believe this was @Fenix Eldritch suggestion; this would fix your code so the timer only runs ONCE for each "new command":

    timer() 
    {
        llSetColor(<1.0,0.424,0.710>,ALL_SIDES);  //resets color to pink
        llSetTimerEvent(0.0);  // <<== Add this line here
    }

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 367 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...