Event Timer Value Detection?
|
offstar Charming
Registered User
Join date: 26 Dec 2004
Posts: 22
|
12-29-2004 09:58
Is there a way to determine the value of a timer which is already running in a script? I wanted to know if there was a way other than making the timer go off every second then counting the number of seconds.
I want an internal function to be able to determine the amount of time the internal timer has been running in an elegant manner. A built in function call, or maybe a nifty coding trick?
Any ideas?
Thanks! =)
|
Shack Dougall
self become: Object new
Join date: 9 Aug 2004
Posts: 1,028
|
12-29-2004 10:09
Save the time when the timer event fires. Then, have a function that subtracts this time from the current time to determine how long it has been since the last timer event.
_____________________
Prim Composer for 3dsMax -- complete offline builder for prims and sculpties in 3ds Max http://liferain.com/downloads/primcomposer/
Hierarchical Prim Archive (HPA) -- HPA is is a fully-documented, platform-independent specification for storing and transferring builds between Second Life-compatible platforms and tools. https://liferain.com/projects/hpa
|
offstar Charming
Registered User
Join date: 26 Dec 2004
Posts: 22
|
12-29-2004 10:23
Interesting, yes! I see that as being a work around, but what about the case where the timer will only ever fire once and we need to see how close to firing we are?
|
Shack Dougall
self become: Object new
Join date: 9 Aug 2004
Posts: 1,028
|
12-29-2004 10:30
From: offstar Charming Interesting, yes! I see that as being a work around, but what about the case where the timer will only ever fire once and we need to see how close to firing we are? Save the time just before or after you call llSetTimerEvent().
_____________________
Prim Composer for 3dsMax -- complete offline builder for prims and sculpties in 3ds Max http://liferain.com/downloads/primcomposer/
Hierarchical Prim Archive (HPA) -- HPA is is a fully-documented, platform-independent specification for storing and transferring builds between Second Life-compatible platforms and tools. https://liferain.com/projects/hpa
|
offstar Charming
Registered User
Join date: 26 Dec 2004
Posts: 22
|
12-29-2004 10:37
Okay, cool. That works as long as the script is in execution, but what if someone derez's the object before the timer fires? I know there is an on_rez functin but can't locate an on_derez function, which I could theoritically use to save the time.
Is there a way to tell when the object the script resides within is about to be put back into inventory?
|
Shack Dougall
self become: Object new
Join date: 9 Aug 2004
Posts: 1,028
|
12-29-2004 11:03
From: offstar Charming Okay, cool. That works as long as the script is in execution, but what if someone derez's the object before the timer fires? I know there is an on_rez functin but can't locate an on_derez function, which I could theoritically use to save the time.
Is there a way to tell when the object the script resides within is about to be put back into inventory? An attached object will get an attach() event when it is detached into the inventory. See also my 2nd reply to your attachment question. Right off hand, I don't know a way to detect when an unattached object dies or goes back to inventory. Other than to have a timer and send it a message every now and then to see if it's alive.
_____________________
Prim Composer for 3dsMax -- complete offline builder for prims and sculpties in 3ds Max http://liferain.com/downloads/primcomposer/
Hierarchical Prim Archive (HPA) -- HPA is is a fully-documented, platform-independent specification for storing and transferring builds between Second Life-compatible platforms and tools. https://liferain.com/projects/hpa
|
Upshaw Underhill
Techno-Hobbit
Join date: 13 Mar 2003
Posts: 293
|
12-29-2004 16:15
Sounds like what you might need is llGetTimeStamp rather than a timer event. It takes a bit of code to make use of it as it looks something like 2004-12-29T00:56:21.785886Z but there's a compare routine already written on the wiki Wiki entry: llGetTimeStampyes attach() fires when you take it off or drop it. I've never tried it but I'm not sure if there's ever a chance for llDie to work to complete kill the item but you can certainly just disable the script if it's been 'used up' (just a guess as to your use  ) either by deleting the script or turning it off. (llRemoveInventory(llGetScriptName()) or llSetScriptState(llGetScriptName(),FALSE) respectively) L8r, UU
|
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
|
12-29-2004 19:03
Or you could use the llGetTime(), llGetAndResetTime(), and llResetTime() functions. When your script calls the llSetTimerEvent() function, have it immediately call llResetTime().
I suppose you want to be able to touch the object and be told the time remaining. So, you touch the object, then subtract llGetTime() from the original float defined in llSetTimerEvent(). Do the proper calculations to separate the seconds and there you have it. As the Wiki warns, this procedure would return an incorrect time if the sim resets after your timer is set.
This brings a question: If the sim is reset, does llSetTimerEvent() get reset as well? And on a llSetTimerEvent() call, does the timer event trigger, then wait the number of seconds indicated... or does it wait the number of seconds, then trigger?
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
12-30-2004 02:32
From: DoteDote Edison Or you could use the llGetTime(), llGetAndResetTime(), and llResetTime() functions. When your script calls the llSetTimerEvent() function, have it immediately call llResetTime().
This brings a question: If the sim is reset, does llSetTimerEvent() get reset as well? And on a llSetTimerEvent() call, does the timer event trigger, then wait the number of seconds indicated... or does it wait the number of seconds, then trigger? llGetTime & et al are effected by TimeDilation. No your llSetTimerEvent does not become unhinged on sim reset.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
offstar Charming
Registered User
Join date: 26 Dec 2004
Posts: 22
|
12-30-2004 09:27
I thought about using time functions which where effected by sim resets and opted out of using these for that reason. Calculating the time stamp then comparing might be a better way to go for my use.
Upshaw Underhill, you are correct the point of using the timer to track this is because the script should 'decay' over time. That is the object which contains the script should stop functioning after some preset usage time. In this case the concept is being applied to a script which simulates a living creature who will eventually die.
The problem with using a timer is that the scripted object can be put back into inventory, escentally putting the creature into hibernation. Which is fine I suppose, but still doesn't give me a convenient way to check age. I would have to set up a timer to fire on a small preset interval, say every second, then update a current age value; which the user could then look at. But I don't really want a timer firing every second for the life time of the script if I can help it. This is more of a concern of load on the sim.
So I suppose I could time stamp at the start of the script and use the timer to periodically update another time stamp of the script and thus the perceived age of the object. The timer could manage the shut off of the script after the preset time as well as allowing the user to calculate the age from the dialog box whenever they want to by comparing stored time stamps.
I guess using the timer and timestamps is going to be my best bet, if I decided that real world time is the best approach for determining age. But on the other side, if when the object containing the script is in hibernation it simply doesn't age (frozen timer) from the perspective of the script, then I can't use timestamps. The result being that the owner can never fully know how much longer that script will be active. This might not be seen as a bad thing given the nature of the object, a living creature in this case, since this might be seen as more realistic to the owner.
|