Jump to content

Timer not working


SubZeroWins
 Share

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

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

Recommended Posts

Your isday variable is mebbe messin stuff up? dunno...

 

this may work...

integer time = 120; //How many seconds between checking

Check()
{
    vector sun_dir = llGetSunDirection(); 
    if (sun_dir.z > 0 ) 
    {   llSay(0, "It is currently day.");     
        //Do something here for when it is DAY.
    }
    else
    {   llSay(0, "It is currently night.");     
        //Do something here for when it is NIGHT.
    }
}

default
{
    on_rez(integer start_param)
    {  llResetScript();
    }    
    state_entry()
    {   Check();
        llSetTimerEvent(time);
    }
    touch_start(integer total_number) 
    {  Check();       
    }
    timer()
    {  Check(); 
    }
}

 

Edited by Xiija
Link to comment
Share on other sites

17 minutes ago, Xiija said:

Your isday variable is mebbe messin stuff up? dunno...

 

this may work...


integer time = 120; //How many seconds between checking

Check()
{
    vector sun_dir = llGetSunDirection(); 
    if (sun_dir.z > 0 ) 
    {   llSay(0, "It is currently day.");     
        //Do something here for when it is DAY.
    }
    else
    {   llSay(0, "It is currently night.");     
        //Do something here for when it is NIGHT.
    }
}

default
{
    on_rez(integer start_param)
    {  llResetScript();
    }    
    state_entry()
    {   Check();
        llSetTimerEvent(time);
    }
    touch_start(integer total_number) 
    {  Check();       
    }
    timer()
    {  Check(); 
    }
}

 

I tried that already, still doesn't work. Thanks.

Link to comment
Share on other sites

That's one of the simplest scripts going. The only way it could fail would be if you mistyped the number 2. I can't imagine another reason . Two seconds is WAY too fast, though. The SL sky doesn't change that fast (neither does the RL sky). Two minutes is ideal.

Link to comment
Share on other sites

9 minutes ago, Rolig Loon said:

That's one of the simplest scripts going. The only way it could fail would be if you mistyped the number 2. I can't imagine another reason . Two seconds is WAY too fast, though. The SL sky doesn't change that fast (neither does the RL sky). Two minutes is ideal.

I set it like

integer time = 2

Is this wrong?

Link to comment
Share on other sites

The missing semicolon would certainly kill it, yes. Even after you fix that, though, I strongly advise leaving the timer set at 120 seconds. Anything faster than that is unrealistic and a waste of server time. The sun simply does not rise or set fast enough to make a faster timer reasonable.

  • Like 1
Link to comment
Share on other sites

I agree with Rolig; in fact, I suggest trying a fresh copy and not changing it, and seeing what it does.

I can understand setting it to something relatively low for testing purposes, also, but 2 seconds is really fast. If you have your script sending you feedback when testing, it'll overwhelm you with chat spam, and that gets annoying fast, too.

If anything, for testing the script personally I would just remove the 0 from the end of 120, leaving the semicolon intact, and wait the twelve seconds to see the changes, if any, then set it back when finished testing the script.

Link to comment
Share on other sites

Missing semicolon was only a typo while posting it.

And yes, Its my land and I run other scripts with no problem.

I will post the modified code Im using for my purposes (there are very few changes though)

integer Countdown=5;
integer IsDay; 

Check() 
{
    vector sun_dir = llGetSunDirection();

    if (sun_dir.z > 0 && IsDay == FALSE)
    {
    IsDay = TRUE;
    } 
    else if (sun_dir.z < 0 && IsDay == TRUE)
    {
    IsDay = FALSE;
    }
Countdown=5;
llSetTimerEvent(1.0);    
} 

default 
{ 
    on_rez(integer start_param) 
    { 
        llResetScript(); 
    } 
     
    state_entry() 
    { 
        vector sun_dir = llGetSunDirection(); 
        IsDay = (sun_dir.z < 0); 
        Check(); 
        llSetTimerEvent(1.0); 
    } 

    timer() 
    {
    Countdown--;
        if(Countdown==-1)
        {
        Countdown=5;
        Check(); 
        }
    } 
}

The problem appears when switching from day to night or the opposite. Its exactly the moment when the timer stops.

Im not that experienced with lsl but I cant see the reason its happening.

Btw, thank you all for your contributions.

Link to comment
Share on other sites

How are you testing this?

I ask because waiting through the SL four hour day cycle can be a bit tedious, so the temptation must be to take a short cut and manipulate the time of day manually. Now, I don't think that using the basic time of day settings will work here. I think you'd need to actually switch Windlight day settings to have an effect. Haven't actually tested this, so I'll log in right now…

ETA: OK, what worked for me was to wear the scripted object as a HUD and then TP to some fixed sun regions that were either always day or always night, and one that had a contrary day cycle completely out of sync with the SL default. The script then correctly identified day and night.

Sundarban - always day.

Selidor - always night (just the night side of sunset)

Skye Neist Point - has it's own idea of when night and day are

I think to shortcut the testing you need to be able to set the Windlight for the region you're in, which means being the owner or an estate manager there. Any other setting will be viewer-side only. 

Edited by KT Kingsley
Link to comment
Share on other sites

10 hours ago, SubZeroWins said:

I tried that already, still doesn't work. Thanks.

I just tried it in a newly rezzed cube, and it's quietly ticking away.

[19:54] Object: It is currently night.
[19:54] Object: It is currently night.
[19:56] Object: It is currently night.
[19:58] Object: It is currently night.
[20:00] Object: It is currently night.

Sent the OP a working cube with the script inside.

Link to comment
Share on other sites

5 hours ago, SubZeroWins said:

Missing semicolon was only a typo while posting it.

And yes, Its my land and I run other scripts with no problem.

I will post the modified code Im using for my purposes (there are very few changes though)


integer Countdown=5;
integer IsDay; 

Check() 
{
    vector sun_dir = llGetSunDirection();

    if (sun_dir.z > 0 && IsDay == FALSE)
    {
    IsDay = TRUE;
    } 
    else if (sun_dir.z < 0 && IsDay == TRUE)
    {
    IsDay = FALSE;
    }
Countdown=5;
llSetTimerEvent(1.0);    
} 

default 
{ 
    on_rez(integer start_param) 
    { 
        llResetScript(); 
    } 
     
    state_entry() 
    { 
        vector sun_dir = llGetSunDirection(); 
        IsDay = (sun_dir.z < 0); 
        Check(); 
        llSetTimerEvent(1.0); 
    } 

    timer() 
    {
    Countdown--;
        if(Countdown==-1)
        {
        Countdown=5;
        Check(); 
        }
    } 
}

The problem appears when switching from day to night or the opposite. Its exactly the moment when the timer stops.

Im not that experienced with lsl but I cant see the reason its happening.

Btw, thank you all for your contributions.

I don't know if you have anything else going on in your script that you've omitted which would require you to decrement the value of Countdown but if not then using a 1 second timer then only performing an action once every 6th time the event is triggered is hideously inefficient, you may as well just remove Countdown entirely and use a longer duration for the timer instead.  Also there's no need for the llSetTimerEvent command in the Check() function since you set a timer in the state_entry event after calling the function and you only need to set the timer event once rather than each time the function is called.  

I'd strongly recommend you heed Roligs advice and use a much slower timer, 1 second (or even 6) is far too rapid for detecting a change that only happens once every few hours (you can always use the changed event to detect changes in sun position when moving between different regions, there really is no need to be using a timer that fast if all you're doing is checking to see if the sun is up).

Additionally I can't help wondering if it would be simpler and more efficient to remove

        vector sun_dir = llGetSunDirection();
        IsDay = (sun_dir.z < 0);

from the state_entry event and replace the multiple if statements in the Check() function with 

Check() 
{
    vector sun_dir = llGetSunDirection();
    IsDay = (sun_dir.z > 0);
} 

so the final script would look something like this...

integer IsDay; 

Check() 
{
    vector sun_dir = llGetSunDirection();
    IsDay = (sun_dir.z > 0);
} 

default 
{ 
    on_rez(integer start_param) 
    { 
        llResetScript(); 
    } 
     
    state_entry() 
    { 
        Check(); 
        llSetTimerEvent(120.0);
    } 

    timer() 
    {
        Check();
    }
    
    changed(integer change)
    {
        if (change & CHANGED_REGION)
        {
            Check();
        }
    }
}

 

Link to comment
Share on other sites

8 hours ago, Fluffy Sharkfin said:

I don't know if you have anything else going on in your script that you've omitted which would require you to decrement the value of Countdown but if not then using a 1 second timer then only performing an action once every 6th time the event is triggered is hideously inefficient, you may as well just remove Countdown entirely and use a longer duration for the timer instead.  Also there's no need for the llSetTimerEvent command in the Check() function since you set a timer in the state_entry event after calling the function and you only need to set the timer event once rather than each time the function is called.  

I'd strongly recommend you heed Roligs advice and use a much slower timer, 1 second (or even 6) is far too rapid for detecting a change that only happens once every few hours (you can always use the changed event to detect changes in sun position when moving between different regions, there really is no need to be using a timer that fast if all you're doing is checking to see if the sun is up).

Additionally I can't help wondering if it would be simpler and more efficient to remove


        vector sun_dir = llGetSunDirection();
        IsDay = (sun_dir.z < 0);

from the state_entry event and replace the multiple if statements in the Check() function with 


Check() 
{
    vector sun_dir = llGetSunDirection();
    IsDay = (sun_dir.z > 0);
} 

so the final script would look something like this...


integer IsDay; 

Check() 
{
    vector sun_dir = llGetSunDirection();
    IsDay = (sun_dir.z > 0);
} 

default 
{ 
    on_rez(integer start_param) 
    { 
        llResetScript(); 
    } 
     
    state_entry() 
    { 
        Check(); 
        llSetTimerEvent(120.0);
    } 

    timer() 
    {
        Check();
    }
    
    changed(integer change)
    {
        if (change & CHANGED_REGION)
        {
            Check();
        }
    }
}

 

I read that a timer's long interval consumes memory so I thought that a 1 second timer would be better, so when using the Countdown and reaching -1 to trigger the function and then start again from 5.

Finally using the original script exactly as it is it does my work.

Though Im very curious, back to my script

integer Countdown=5;
integer IsDay; 

Check() 
{
    vector sun_dir = llGetSunDirection();

    if (sun_dir.z > 0 && IsDay == FALSE)
    {
    IsDay = TRUE;
    llOwnerSay("DAY");
    } 
    else if (sun_dir.z < 0 && IsDay == TRUE)
    {
    IsDay = FALSE;
    llOwnerSay("NIGHT");
    }
Countdown=5;
llSetTimerEvent(1.0);    
} 

default 
{ 
    on_rez(integer start_param) 
    { 
        llResetScript(); 
    } 
     
    state_entry() 
    { 
        vector sun_dir = llGetSunDirection(); 
        IsDay = (sun_dir.z < 0); 
        Check(); 
        llSetTimerEvent(1.0); 
    } 

    timer() 
    {
    Countdown--;
        if(Countdown==-1)
        {
        Countdown=5;
        llOwnerSay("CHECK");
        Check(); 
        }
    } 
}

The timer was printing "CHECK" every 5 seconds but when the day became night I was expecting it to print "NIGHT"  but it didn't and it continued to print "CHECK".

Link to comment
Share on other sites

11 hours ago, animats said:

I just tried it in a newly rezzed cube, and it's quietly ticking away.


[19:54] Object: It is currently night.
[19:54] Object: It is currently night.
[19:56] Object: It is currently night.
[19:58] Object: It is currently night.
[20:00] Object: It is currently night.

Sent the OP a working cube with the script inside.

Thank you pal.

Link to comment
Share on other sites

  • Lindens

I think that I see the what the issue may be.  The problem is not your timer.  From your testing you can see that it is happily ticking away.

The problem is llGetSunDirection().  The current implementation of this function returns a vector to the current position of the region's sun.  The keyword here is "region".   The region's sun is not affected by whatever Windlight settings are applied to the region. (Think of it as pointing to an invisible sun... that gives its heat to everyone...:P

When EEP rolls to the grid, this will no longer be the case.  llGetSunDirection is being changed to accurately give you a vector pointed to the sun as calculated by the environment settings.  There will additionally be a function added called llGetMoonDirection that will provide a vector pointing to the moon since it will be able to be moved independently.

  • Like 5
Link to comment
Share on other sites

2 hours ago, Rider Linden said:

I think that I see the what the issue may be.  The problem is not your timer.  From your testing you can see that it is happily ticking away.

The problem is llGetSunDirection().  The current implementation of this function returns a vector to the current position of the region's sun.  The keyword here is "region".   The region's sun is not affected by whatever Windlight settings are applied to the region. (Think of it as pointing to an invisible sun... that gives its heat to everyone...:P

When EEP rolls to the grid, this will no longer be the case.  llGetSunDirection is being changed to accurately give you a vector pointed to the sun as calculated by the environment settings.  There will additionally be a function added called llGetMoonDirection that will provide a vector pointing to the moon since it will be able to be moved independently.

EEP?

Link to comment
Share on other sites

Thanks, @Rider Linden.   I wasn't aware llSetAgentEnvironment and llAdjustAgentEnvironment were in the pipeline (now I come to think of it, I may have seen an announcement at one point but I'd forgotten about it).

Inara's article is dated last June, so almost a year ago.    How are the functions progressing?   Is there an ETA for them?

Link to comment
Share on other sites

  • Lindens

It has been a long process but I'm nearing a point that I'll be able to start rolling out an initial project viewer very soon now. The most complex part has turned out to be the addition of settings objects to inventory, I think this is the first new inventory type that we've added since mesh so the change has taken quite a bit of archaeology, and more than a little prayer, to make.  

The first project viewer will most likely not have the scripting functions since I want to get settings into creator's hands as quickly as possible.  They will follow soon after though.

  • Like 3
Link to comment
Share on other sites

  • 1 year later...

Rider, it's 1.5 years later. Can you confirm or disconfirm this, please?

 

Quote

The current implementation of this function returns a vector to the current position of the region's sun.  The keyword here is "region".   The region's sun is not affected by whatever Windlight settings are applied to the region. (Think of it as pointing to an invisible sun... that gives its heat to everyone...:P

When EEP rolls to the grid, this will no longer be the case.  llGetSunDirection is being changed to accurately give you a vector pointed to the sun as calculated by the environment settings.  There will additionally be a function added called llGetMoonDirection that will provide a vector pointing to the moon since it will be able to be moved independently.


 

 

Link to comment
Share on other sites

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