Jump to content
You are about to reply to a thread that has been inactive for 114 days.

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

Recommended Posts

Posted (edited)

I had assume that `state_entry()` would only run once when a script first runs.

If that script is in an object that is attached as a HUD, then my understanding was that only `attach(key attached)` runs each time it is attached.

I have a HUD that sets a timestamp in state_entry(). Then in future the HUD needs to deactivate after a fixed lifespan of 14 days
The problem is that after 3 days it still reports that 14 days are remaining. Somehow `resetTimeSeconds` is getting reinitialised when wearing or detaching the HUD

 

integer resetTimeSeconds;

default
{
    state_entry()
    {
        resetTimeSeconds = (integer) llGetTime();         
        llOwnerSay("\n\n- HUD initialised -");        
        llSetTimerEvent(timerInterval);
    }

	attach(key attached)
    {
        if (attached != NULL_KEY)  // object has been detached
        {
            // do stuff when attached
        }
    }

}

Then in `attach()` we simply compare the time, as we also do in the `timer()` method.

However it seems to keep resetting.

Would a script reset when a worn object is taken off and goes back to being just an inventory item?

Is it  possible to make variables persist between taking a HUD on and off?

 

Edited by Remi Alpha
Posted (edited)

Event attach(key attached) runs when something is attached AND when something is detached.
On attach it returns a key. On detach it returns an empty key.

 

Also, unless you have a llResetScript() in the on_rez() event, the script won't reset when taken back into inventory.

Edited by Ron Khondji
Posted
37 minutes ago, Ron Khondji said:

Event attach(key attached) runs when something is attached AND when something is detached.
On attach it returns a key. On detach it returns an empty key.

Yes I know that, and that works. 

 

37 minutes ago, Ron Khondji said:

unless you have a llResetScript() in the on_rez() event, the script won't reset when taken back into inventory.

But the problem is that the value of `resetTimeSeconds` seems to be being reset. Not every time but after say leaving it 24 hours it has reset to a new timestamp.

Posted

What do you mean when you say "it seems to keep resetting"?

After the script has reset, I'd expect 

resetTimeSeconds = (integer) llGetTime(); 

to return 0.

Otherwise, since 

Quote
  • Script time is the amount of real-world time that the script has been in a running state. It is unaffected by time dilation, but it does not count time while the script is suspended, the user is offline (when in an attachment), the object is in inventory rather than rezzed, etc.

https://wiki.secondlife.com/wiki/LlGetTime

I'd expect it to return whatever was its value before the attachment was detached.

What is it actually returning when you re-attach it?

Posted (edited)
30 minutes ago, Innula Zenovka said:

What do you mean when you say "it seems to keep resetting"?

The value goes back to (integer) llGetTime();* despite the script not being reset. Only by detaching and reattaching.

*Edit / note: I have just realised that (integer) llGetTime();  is effectively always going to be 0 inside of state_entry()  because it's time since the script ran (I had previously assumed it was a global time, more like time since the unix epoch). So I don't need to set any value at this point. The issue then is that llGetTime() is later returning close to zero when it should be showing several days.

I have added some more detailed debugging code to work out what's going on, but it seems like the script is getting reset.

Crashing the cause?

I had another thought. SL crashes a lot for me, especially when TPing. This happens several times a day. Could a HUD script get reset when:

1. Attach HUD

2. Viewer crashes

3. Relog 

?

I have noticed that states get lost when crashing, for example my HUD-controlled avatar alpha might revert to the configuration from when I previously logged in, after a crash. So maybe that could be what I am seeing.

Edited by Remi Alpha
  • Thanks 1
Posted

This is what I'm seeing:

Quote


[06:08] Object: State entry:llGetTime ==0.112024
[06:08] Object: attach event at 2024-08-18T13:08:14.284718Z: llGetTime == 8.622929
[06:08] Object: detached at 2024-08-18T13:08:31.014338Z: llGetTime == 25.355360
[06:09] Object: attach event at 2024-08-18T13:09:01.484521Z: llGetTime == 27.356600
[06:10] Object: detached at 2024-08-18T13:10:14.949468Z: llGetTime == 100.823400
[06:16] Object: attach event at 2024-08-18T13:16:25.822372Z: llGetTime == 102.846000

default
{
    state_entry()
    {
       llOwnerSay("State entry:llGetTime =="+(string)llGetTime());
    }
    
    attach(key id){
        if(id){
         llOwnerSay("attach event at "+llGetTimestamp()+": llGetTime == "+(string)llGetTime());   
        }
        else{
            llOwnerSay("detached at "+llGetTimestamp()+": llGetTime == "+(string)llGetTime());
        }   
        
    }
}

 

Posted (edited)
2 hours ago, Remi Alpha said:

The issue then is that llGetTime() is later returning close to zero when it should be showing several days.

llGetTime returns the time the script has been running. I understood that your object isn't rezzed all the time, and not being rezzed means the script's not running, you might be wanting llGetTimestamp (edit: or llGetUnixTime) instead.

Scripts reverting to a previous state from a crash isn't unheard of, but I think this is more an issue with llGetTime not doing what you think it is doing, it's meant more for low-duration timekeeping only while rezzed.

Edited by Frionil Fang
  • Like 2
  • Thanks 1
Posted (edited)
7 hours ago, Frionil Fang said:

llGetTime returns the time the script has been running. I understood that your object isn't rezzed all the time, and not being rezzed means the script's not running, you might be wanting llGetTimestamp (edit: or llGetUnixTime) instead.

Scripts reverting to a previous state from a crash isn't unheard of, but I think this is more an issue with llGetTime not doing what you think it is doing, it's meant more for low-duration timekeeping only while rezzed.

Ah..... yes this is it. 

I *assumed* (there's that word lol) that it was a universal time. What's happening is it stops when the hud is off. So that's no use.

Thank you! I will use llGetUnixTime, which is what i thought i was using, if that makes sense.

Edited by Remi Alpha
Posted (edited)
7 hours ago, Innula Zenovka said:

This is what I'm seeing:

default
{
    state_entry()
    {
       llOwnerSay("State entry:llGetTime =="+(string)llGetTime());
    }
    
    attach(key id){
        if(id){
         llOwnerSay("attach event at "+llGetTimestamp()+": llGetTime == "+(string)llGetTime());   
        }
        else{
            llOwnerSay("detached at "+llGetTimestamp()+": llGetTime == "+(string)llGetTime());
        }   
        
    }
}

 

Thank you, yes i saw similar but then was confused why it hadn't advanced after 24 hours.

.What I thought was the script resetting was in fact due to the fact it hadn't been running when detached because i was using llGetTime() instead of llGetUnixTime()

Edited by Remi Alpha
  • Like 1
You are about to reply to a thread that has been inactive for 114 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
×
×
  • Create New...