multiple timers in a script
|
|
Echo Dragonfly
Surely You Jest
Join date: 22 Aug 2004
Posts: 325
|
11-20-2006 13:13
I am working on an oil lamp, allready uses a timer to check for sun pos(auto on and off). I would also like to add a flickering effect to the light itself, which, as I understand, requires another timer, changing the color in the prim point light call using multiple vectors from a list. Is this able to be done? I checked the wiki, but no ifo there.
I am self teaching myself,so any info would be a huge help, thx.
_____________________
Creativity represents a miraculous coming together of the uninhibited energy of the child with its apparent opposite and enemy, the sense of order imposed on the disciplined adult intelligence. Norman Podhoretz ...................... If quizzes are quizzical, what are tests?  ............................ Do illiterate people get the full effect of Alphabet Soup? 
|
|
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
|
11-20-2006 13:23
You can only have one timer running at a time for each script. There are two obvious options as far as I can see: one, have your flicker timer increment another counter each time it fires, and when that reaches a certain level, look for sun position. e.g. integer gCount = 0;
...
llSetTimerEvent(1.0);
...
timer() { flicker(); if (++gCount == 300) { check_sun_position(); // so every five minutes gCount = 0; } }
Or, you could have two scripts running in the same object, one to check sun position every so often, the other to do the flicker. The sun position script could then tell the flicker/illumination script to turn off when it's light, via a link message.
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!
http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal
http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
11-20-2006 13:35
From: Ordinal Malaprop timer() { flicker(); if (++gCount == 300) { check_sun_position(); // so every five minutes } }
Probably good idea would be to add the gCount -= 300; as part of the if() {} conditional, otherwise the counter is going to equal 300 just once there ^^; that or maybe slightly more flexible if( (++gCount % 300) == 0 ) { // whatever }
... which has a bit of advantage as it makes running multiple events with different call frequency easier ^^;;
|
|
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
|
11-20-2006 13:38
Doh, yes, I forgot to zero the counter, even after telling myself "don't forget to zero the counter". I am an idiot.
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!
http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal
http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
11-20-2006 14:39
At 1, 2, 5 & 6 minutes etc this will say "timer". At 3 minutes it will say "timer_b" instead. At 4 minutes it will say "timer_c"..................... integer timer_b = 1;
default{ state_entry() { llSetTimerEvent(60.0); } timer(){ timer_b += 1; if(timer_b == 3){ llSay(0, "timer b"); } else if(timer_b == 4){ llSay(0, "timer c"); timer_b = 1; } else{ llSay(0, "timer"); } } }
Editted because I did it free hand in the window here 
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
|
11-20-2006 14:49
Or for some randomness to the flickering: float timeElapsed = 0.0;
state_entry() { llSetTimerEvent(0.01); }
timer() { float add = 0.5 + llFrand(0.5); timeElapsed += add;
if (timeElapsed >= 300.0) { // Do sun check and actions timeElapsed = 0.0 } // Flicker effect llSetTimerEvent(add); }
_____________________
Computer (Mac Pro): 2 x Quad Core 3.2ghz Xeon 10gb DDR2 800mhz FB-DIMMS 4 x 750gb, 32mb cache hard-drives (RAID-0/striped) NVidia GeForce 8800GT (512mb)
|
|
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
|
11-20-2006 15:08
_____________________
-Seifert Surface 2G!tGLf 2nLt9cG
|
|
Jopsy Pendragon
Perpetual Outsider
Join date: 15 Jan 2004
Posts: 1,906
|
11-20-2006 15:11
// crude hack! not test-compiled, verify syntax, etc, etc. default { state_entry() { llSetTimerEvent(5.0); // for flicker llSensorRepeat( "NOSUCHTHING", "x", AGENT, 0.0, 0.0, 360.0); // for sun sensor. } timer () { // flickerstuff } no_sensor(integer n) { // sun detection stuff } } You could also just break it into two scripts, the effect and flicker timer in one, along with a link_message() event handler. In the other your sun-watcher timer that sends an llMessageLinked() command to the first script. 
_____________________
* The Particle Laboratory * - One of SecondLife's Oldest Learning Resources. Free particle, control and targetting scripts. Numerous in-depth visual demonstrations, and multiple sandbox areas. - Stop by and try out Jopsy's new "Porgan 1800" an advanced steampunk styled 'particle organ' and the new particle texture store!
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
11-20-2006 20:59
Here's another possibility: (Note: Not compiled or tested, as SL is down. It's pseudocode anyway.) float FLICKER_PERIOD = ...; float SUN_CHECK_PERIOD = ...;
float nextFlickerTime; float nextSunCheckTime;
flicker(float currTime) { ...
nextFlickerTime = currTime+FLICKER_PERIOD; }
checkSun(float currTime) { ...
nextSunCheckTime = currTime+SUN_CHECK_PERIOD; }
setTimer(float currTime) { if (nextFlickerTime < nextSunCheckTime) { llSetTimerEvent(nextFlickerTime - currTime); } else { llSetTimerEvent(nextSunCheckTime - currTime); } }
...
default { state_entry() { float currTime = llGetTime(); nextFlickerTime = currTime+FLICKER_PERIOD; nextSunCheckTime = currTime+SUN_CHECK_PERIOD; setTimer(currTime);
... }
timer() { float currTime = llGetTime();
if (currTime >= nextFlickerTime) { flicker(currTime); }
if (currTime >= nextSunCheckTime) { checkSun(currTime); }
setTimer(currTime); } }
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
11-20-2006 21:27
you would really save yourself alot of prim updates and headache if you used an animated texture ...
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
11-21-2006 00:32
From: Osgeld Barmy you would really save yourself alot of prim updates and headache if you used an animated texture ... Or particles, I suppose, but I assume the point was to flicker the light illuminating the surroundings, not just the lamp itself. I've actually done this with some light prims in a rotating object, but in this case that would require multiple objects, possibly with rezzing....
|