Jump to content

Setting timer on an attachment


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

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

Recommended Posts

Hello. I am working on an attachment that an avatar will wear for a set amount of time (let's say 100 hours). I know how to write the script to count how long the avatar has been wearing the attachment, but that counter restarts whenever the avatar logs off and logs back on SL...so they will never meet the 100 hours.

Is it possible to store the amount of time worn somewhere, so when the avatar logs back on, it picks up from that point?

I do not want to use the unix time, because the avatar could just stay logged out of SL for the 100 hours, and the script would be pointless.

Thanks for any help.

Link to comment
Share on other sites

If I'm not mistaken, llGetTime() will detail the amount of time an object has been in-world (rezzed or attached) since script reset or llResetTime(). The other solution is to just add to a global variable (or linkset data key / description field) on a timer.

  • Thanks 1
Link to comment
Share on other sites

8 hours ago, Quistess Alpha said:

If I'm not mistaken, llGetTime() will detail the amount of time an object has been in-world (rezzed or attached) since script reset or llResetTime(). The other solution is to just add to a global variable (or linkset data key / description field) on a timer.

The llGetTime() gave me just what I needed. Thanks!!

  • Like 1
Link to comment
Share on other sites

do not rely on llGetTime(), as this is susceptible to lag and other script runtime factors.

You want to save llGetUnixTime() as a variable either using the object keystore or as a variable in the script itself.

call variable = llGetUnixtime(); on attach to save the unix time when the object was attached, and then periodically check against that to determine if their wear time has ended or not.

an example:
 

integer attachedAt;
float expieryAt = 10; /* 10 seconds */

/* checking expiery global function */
checkexp() {
	if((attachedAt + expieryAt) <= llGetUnixTime()) {
		llSetTimerEvent(0);
    	llDetechFromAvatar();
    }
}

default {    
    run_time_permissions(integer perms) {
		/* trigger most your events from here. this confirms they've attached and given permissions to detach. */
    	if(perms & PERMISSION_ATTACH) {
        	/* Check if we already set an attached time to not overwrite it */
			if(!attachedAt) {
				attachedAt = llGetUnixTime();
				llSetTimerEvent(0.1);
			} else {
				llSetTimerEvent(0.1);
			}
        }
    }

	on_rez(integer rez) {
		llSetTimerEvent(0);
		llRequestPermissions(wearer, PERMISSION_ATTACH);
	}
	
	timer() {
		checkexp();
	}
}

 

Link to comment
Share on other sites

11 hours ago, alexx Ohmai said:

call variable = llGetUnixtime(); on attach to save the unix time when the object was attached, and then periodically check against that to determine if their wear time has ended or not.

yes, but the OP wants to ignore time when the object is ~not attached. It wouldn't be too hard to add a little routine in the detach event to manage a global accumulator, but the detach event is not 100% guaranteed to run before the object has finished detaching, which could lead to a rare over-accumulation  a more-correct implementation might be simply:

integer gAttachedFor = 0;
integer gUnixLast;
default
{   state_entry()
    {   llSetTimerEvent(5.0); // anything less than 1.0 is inefficient.
     	gUnixLast = llGetUnixTime();
    }
    timer()
    {   integer t = llGetUnixTime();
        integer diff = t-gUnixLast;
        gUnixLast = t;
        if(diff<10) // an overly generous allowance for lag.
        {   if(llGetAttached()) // arguably should be nested in opposite order.
            {  gAttachedFor+=diff;
            }
        }
        //if(gAttachedFor>X){...}
    }
}

but llGetTime() is nice for its simplicity.

  • Like 1
Link to comment
Share on other sites

51 minutes ago, Quistess Alpha said:

but llGetTime() is nice for its simplicity.

Besides, unless the OP is truly concerned about split second precision, the little bit of lag error in using llGetTime isn't going to make any difference at all. I suspect his application isn't like timing an Olympic track event; it's just going to be happy to know that it's about time to end.

  • Like 2
Link to comment
Share on other sites

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