|
Keera Zenovka
Registered User
Join date: 23 Mar 2007
Posts: 35
|
10-29-2007 17:30
I have a chunk of code and I want it to repeat, cycle through (in this case rotate) constantly until another event interrupts it. Eventually it will be tied to an animation, and when the animation stops, it should stop rotating. When the animation starts, it should start rotating again. For this reason I can't use a "loop". I need to interrupt the cycle and from reading these forums I now know I should use a timer. This is my first experience using timers, and I'm not sure how to create a repetitive cycle within the timer. It was suggested that I use a global variable and increment it each timer event. Can someone show me how this is done?
default { state_entry() { llSetTimerEvent(0.1); }
timer() { RotFromEdge(50, Z_NEG, Y_AXIS); llSleep(.001); RotFromEdge(-50, Z_NEG, Y_AXIS); llSleep(.001); RotFromEdge(215, Z_NEG, Y_AXIS); llSleep(.001); RotFromEdge(-215, Z_NEG, Y_AXIS); llSleep(.001); } }
|
|
Phoenix Ristow
Registered User
Join date: 11 Sep 2006
Posts: 9
|
10-29-2007 18:57
integer x; //Global Variable default { state_entry() { llSetTimerEvent(0.1); x=0; } timer() { x++; // same as x = x + 1 if(x< 100) //10 seconds derived from 100 * .1 seconds { RotFromEdge(50, Z_NEG, Y_AXIS); llSleep(.001); RotFromEdge(-50, Z_NEG, Y_AXIS); llSleep(.001); RotFromEdge(215, Z_NEG, Y_AXIS); llSleep(.001); RotFromEdge(-215, Z_NEG, Y_AXIS); llSleep(.001); } else { x=0; //if you just want to start the time over //llSetTimerEvent(0.0); - if you want to stop the timer } } } From: Keera Zenovka I have a chunk of code and I want it to repeat, cycle through (in this case rotate) constantly until another event interrupts it. Eventually it will be tied to an animation, and when the animation stops, it should stop rotating. When the animation starts, it should start rotating again. For this reason I can't use a "loop". I need to interrupt the cycle and from reading these forums I now know I should use a timer. This is my first experience using timers, and I'm not sure how to create a repetitive cycle within the timer. It was suggested that I use a global variable and increment it each timer event. Can someone show me how this is done?
default { state_entry() { llSetTimerEvent(0.1); }
timer() { RotFromEdge(50, Z_NEG, Y_AXIS); llSleep(.001); RotFromEdge(-50, Z_NEG, Y_AXIS); llSleep(.001); RotFromEdge(215, Z_NEG, Y_AXIS); llSleep(.001); RotFromEdge(-215, Z_NEG, Y_AXIS); llSleep(.001); } }
|
|
Keera Zenovka
Registered User
Join date: 23 Mar 2007
Posts: 35
|
10-29-2007 22:14
Thanks - that works!
|