Timer Events
|
Travis Lambert
White dog, red collar
Join date: 3 Jun 2004
Posts: 2,819
|
01-06-2005 15:42
Hi,
I'm trying to create a script that changes textures at certain times of day automatically.
For example:
8:00am - llSetTexture "EnjoyTheCoffee" 9:00am - llSetTexture "default" 12:00pm - llSetTexture "TimeForLunch" 1:00pm - llSetTexture "default" 9:00pm - llSetTexture "GoodNight" 10:00pm llSetTexture "default"
Basically, so i can change a texture on a prim for an hour or so, then change it back to default. I know there's a function to Get Time, and I could possibly check against that time periodically... but can I do this without creating a bunch of lag? I'm not really concerned about response time... if it was a minute off in changing the texture, it really wouldn't matter.
Any ideas or suggestions would be greatly appreciated!
Thanks!
Travis
|
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
|
01-06-2005 16:07
OK sound like a cool script. What do you need help with?
I would set the script on compile to check the time. To have it figure out what texture to use, and calculate the time to the next event. Witch would be used to set the timer. When the event fired I would have it check the time again. To make sure it's still sinked with the server, and then find then calculate the time to the next timer event and set it.
I would formate the list with the following formate. "time:texture;"
|
Travis Lambert
White dog, red collar
Join date: 3 Jun 2004
Posts: 2,819
|
01-06-2005 16:58
I guess I should have stated that my scripting skills blow. I'm ok at modifying existing scripts, and putting together simple functions from scratch. Doing constant checks, and making sure that it doesn't cause unneccesary lag - I'm lost on.
Any code examples anyone could suggest that I could run with would be hugely helpful.
Thanks!
|
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
|
01-06-2005 17:01
It depends if you want the texture to change at the very minute the time changes to a new hour, or if you can deal with it changing 5-10mins. later within that hour. If you can deal with the latter, I'd say use a timer set at 5 or 10 minute intervals to check the current llGetWallClock(). That function returns the seconds since midnight San Fran time and there's 3600 per hour (3600 would be 1am.) If the seconds > 28800 & seconds < 32400 then it's within the 8am hour. llSetTexture("8am", ALL_SIDES). Of course, you'd have to do math to calculate for your own time zone. If you want the texture to change on the hour, you could initialialize the script near the top of the hour and have it run llSetTimerEvent(1.0) after changing your texture. When the exact top-of-hour second is reached, llSetTimerEvent(3540.0). When the timer event triggers after 59 minutes, call llSetTimerEvent(1.0) again until it hits the hour. The script will sit mostly idle for 59 minutes each hour, then hammer each second for a minute every hour. default { state_entry() { llSetTimerEvent(1.0); } timer() { llSetTimerEvent(1.0); if(llGetWallClock() >= 3600 & llGetWallClock() <= 3605) { llSetTexture("1am Texture", ALL_SIDES); llSetTimerEvent(3540.0); } if(llGetWallClock() >= 7200 & llGetWallClock() <= 7205) { llSetTexture("2am Texture", ALL_SIDES); llSetTimerEvent(3540.0); } } }
|
Nexus Nash
Undercover Linden
Join date: 18 Dec 2002
Posts: 1,084
|
01-06-2005 18:46
From: someone llSetTimerEvent(3540.0). When the timer event triggers after 59 minutes, call llSetTimerEvent(1.0) again until Bad idea, if timedialation is not 1.00 this will be way off. And time dialation is never 1.00! All you have to remember when using timers is how often they trigger and what they do when they trigger! I remember a long way back I used to have lights come on auto at my place. I set the timer for 300 seconds which was totally sufficient. For your purpose I would use the script above, just replace that 1.0 by at least 60.0! Happy scripting!
|
Travis Lambert
White dog, red collar
Join date: 3 Jun 2004
Posts: 2,819
|
01-06-2005 21:10
Thanks, guys. I guess the parallel of what I'm trying to accomplish is to run a sort of "scripted" cron job. My biggest concern is *causing* lag... if the event itself is slightly time-lagged, its relatively unimportant. A 15 minute delay? well... maybe important if my "cron job" only has an hour duration. Going to play around with DoteDote's example some more combined with Nex's suggestion - If I come up with something that works well, I'll post it. Thanks again! This is exactly the start I needed  Travis
|
Danny DeGroot
Sub-legendary
Join date: 7 Jul 2004
Posts: 191
|
01-06-2005 21:50
Maybe converge on the target time by half-steps? Just a thought: get the target wallclock value for your next job and read the timeclock now. Then, set a timer event for half the timespan. Wake up and repeat until you converge to within some fairly small threshold of the actual event time, and then just ride it out for a second or two, reading the clock as often as necessary to get an acceptable start time. Or, maybe better yet, if you're already within an acceptable threshold, just go ahead and fire off the job. That seems to me to be a reasonably efficient way to adjust for time dilation as you approach your target time, while minimizing your use of sim resources. I admire your efforts at good citizenship, BTW  == danny d.
|
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
|
01-06-2005 23:57
I spent some time today writing a script to do what you want. It figure out the difference between the current time and the next alarm. Adjusts for the average sim lag. And bunch of other technical details, with I'm not going to mention. I'll just say each alarm time is stored in a list, and you could have alarms spaced every couple of seconds, and every couple of hours together, with out impacting sim performance. (unless you set about a million alarm times)
Right now I'm ironing out the bugs. if you want to see what it looks like. It's up in dari, next to the color changing hair script, and the open sources dance bracelet.
|
Jason Keegan
Registered User
Join date: 20 Apr 2004
Posts: 26
|
01-07-2005 03:18
Heya, not sure if this is what you are after, but thought it may help anyways  //Delay between each time check integer delay = 30;
//list of times and texture to set to. list time_of_day = ["03:09","texture1", "03:10", "texture2", "03:11", "texture3", "03:12", "texture4" ];
//using the usual wallclock method time() { integer total_seconds = (integer)llGetWallclock(); integer hours = total_seconds / 3600; integer minutes = (total_seconds % 3600) / 60; string wallclock = ""; if (hours < 10) wallclock += "0"; wallclock += (string)hours; wallclock += ":"; if (minutes < 10) wallclock += "0"; wallclock += (string)minutes; //check to see if the time is in the list, if so get the position. integer pos = llListFindList(time_of_day,[wallclock]); //if the time is not in the list it returns the value of -1. if (pos != -1) { //If the value is greater than -1 then set the texture which is found next to the the time, in the list. pos + 1
string texture = llList2String(time_of_day, pos + 1);
// key texture = llList2Key(time_of_day, pos + 1);
llSetTexture(texture, ALL_SIDES); } }
default { state_entry() { llSetTimerEvent(delay); time(); }
timer() { time(); } on_rez(integer start_param) { llResetScript(); } }
Again, Hope it helps. - Jason Keegan.
|
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
|
01-07-2005 05:53
Great script, looks very effishent. Acording to wiki. llGetTimeOfDay() can be fical. Private sims can lock the sun , witch means the clock will not restart every 4 hours like it's subposto. And if the sim is rebooted, the time changes, but the real time dose not. But cool script.
|
Jason Keegan
Registered User
Join date: 20 Apr 2004
Posts: 26
|
01-07-2005 06:52
Removed the use of llGetTimeOfDay(), It was in the original script that I copied the wallclock from to save time, lol. That will teach me. Thanks for pointing out Kurt.  Anyway the posted script will work fine. - Jason Keegan.
|
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
|
01-07-2005 07:09
I'ms erprise your using hour insted of the standard sls unit of time.
|
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
|
01-07-2005 18:01
//creator: Kurt Zidane //vertion: 0.001 //copy right: all rights reserved //description: use the current walltime to find the current event in a list of events
//globals
//settings //fps sampling integer maxNumberOfSamples = 200 ; //list formating //data pos for timeChange integer fFormatLength = 2 ; integer fTime = 0 ; integer fName = 1 ; //time float oneHour = 3600.0 ; float maxTime = 43200.0 ; //24 hours
//dynamic //alarm list, aka data list list timeChange = [] ; //fps sampling list fpsSample = [] ;
//notes:
//funtions // read a list of floats. adding all the values together. It then returns that value devided by the number of floats read. // note: totalValue / max == 0/0 or #/0 may result in faliure? float avrageFloatValue ( list floats ) { float totalValue = 0.0; integer max = llGetListLength ( floats ); integer counter; for ( counter = 0; counter < max; counter++ ) { totalValue += llList2Float ( floats, counter ); } return ( totalValue / (float)max ); }
// crops a list by the max length //note: funtion code has been trimed for performance, sacing some oop standards list trimList ( list inList, integer max ) { integer size = llGetListLength ( inList ); integer diffrence = size - max; if ( diffrence > 0 ) { return llList2List ( inList, diffrence, ( size - 1 ) ); } else { return inList; } }
//uses globals //profiles time dilation float avrageDilation ( ) { fpsSample += llGetRegionTimeDilation ( ); fpsSample = trimList ( fpsSample, ( maxNumberOfSamples ) ); return avrageFloatValue ( fpsSample ); }
//becuase the decolration of global vierables prohibits math list settingtimeChange() { return [ oneHour * 8.0 ,"chill@lash" , oneHour * 9.0 ,"cillevning" , oneHour * 12.0 ,"lash at the gezzebo" , oneHour * 13.0 ,"cillevning" , oneHour * 21.0 ,"man on the sims" , oneHour * 22.0 ,"waterHouse" , oneHour * 24.0 ,"pinkName" ]; }
//uses the current time to find what alarm is active. //returns the posistion of current alarm by it's posistion in list //Notes: // Asumes all time in list is are in order of alarms starting at 00:01 to 24:00. // Time is not formated in hour or in 10:10 it is in seoconds as a float // list include information other then alarm times //Disucstion: // if there are two alarm one at 3:00 and another at 4:00 // then 5:00 is part of alarm 4:00 // and 2:00 is also part of alarm 4:00 ( if current time is less then the first alarm time in list, then it is part of the alst time in list ) // and 3:00 to 3:59 is part of alarm 3:00 integer findEvent ( list valList, float time ) { integer setPoint = 0; integer listSize = llGetListLength ( valList ); integer counter = 0; float eventTime = llList2Float ( timeChange, ( counter + fTime ) ); if ( time < eventTime ) { setPoint = llGetListLength ( valList ) - fFormatLength; } for ( counter = 2; counter < listSize && time > eventTime; counter = counter + fFormatLength ) { setPoint = counter - fFormatLength; eventTime = llList2Float ( timeChange, ( counter + fTime ) ); }
return setPoint; }
//add change to currentNumber, and then uses max to make sure the resolts is in range, // and then returns the resolts. integer counter ( integer currentNumber, integer change, integer max) { integer value = currentNumber + change;
for ( ; value < 0 ; ) { value += max; } for ( ; value >= max; ) { value -= max; }
return value; }
//retreviews texture name from input list. Assumes format is 2 long and 2 is the texture string getTextureName ( list valList, integer pos ) { return llList2String ( valList, ( pos + fName ) ); }
//returns the time diffrence between to times formated in floats float computTimer ( float currentTime, float goalTime ) { float output; if ( goalTime > currentTime ) { output = ( ( goalTime - currentTime ) ); } else { output = ( goalTime + ( maxTime - currentTime ) ); } return output; }
string runTime () { //preProssess float time = llGetWallclock(); integer listSize = llGetListLength ( timeChange ); integer currentEventNum = findEvent( timeChange, time ); integer nextEventNum = counter ( currentEventNum, fFormatLength, listSize ); float currentEventTime= llList2Float ( timeChange, currentEventNum + fTime ); float nextEventTime = llList2Float ( timeChange, nextEventNum + fTime ); float timeDiffrence = computTimer ( time, nextEventTime ); float timerTime = timeDiffrence * avrageDilation(); //out put string textureName = getTextureName ( timeChange, currentEventNum ); llSetTimerEvent ( timerTime ); //debug llWhisper ( 0, "Data List: " + (string)timeChange ); llWhisper ( 0, "Current Event #: " + (string) currentEventNum ); llWhisper ( 0, "Current Event Time: " + (string) currentEventTime ); llWhisper ( 0, "Current Time: " + (string) time ); llWhisper ( 0, "Next Rvent #: " + (string) nextEventNum ); llWhisper ( 0, "Next Event Time: " + (string)nextEventTime ); llWhisper ( 0, "Time to Next Rvent: " + (string) timeDiffrence ); llWhisper ( 0, "Dilation: " + (string) avrageDilation() ); llWhisper ( 0, "Timer Dilated: " + (string)timerTime ); llWhisper ( 0, "Alarm Name: " + textureName ); //return of out put return textureName; }
//settexture by passed name, no error correction included. setTexture ( string name ) { llSetTexture ( name, 0 ); llScaleTexture ( 1.0, 1.0, 0 ); }
default { state_entry () { //calculating alarm times timeChange = settingtimeChange(); //prossess setTexture ( runTime ( ) );
}
touch_start ( integer num ) { setTexture ( runTime ( ) ); } timer () { setTexture ( runTime ( ) ); } }
|