Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Event Timer issues

Mustelid Carnot
Made from quality ferrets
Join date: 7 Sep 2005
Posts: 106
09-11-2005 23:15
I just can't seem to get an event timer to do jack for me. No matter what I do, it seems to be totally ignored in my scripting. It looks like a simple enough command; am I missing something fundimental here?
I'm working on a blinking image, and using a code pretty well verbatum from elsewhere, yet I just cannot, cannot get it to work. Anyone see what I'm doing wrong?

CODE

default {
state_entry()
{
llSetTimerEvent(120);
}

timer(){
llSetTextureAnim(ANIM_ON | PING_PONG | LOOP, ALL_SIDES, 2, 2, 0, 0, 2.0);
}
}


Any insight appreciated!
FireEyes Fauna
Registered User
Join date: 26 Apr 2004
Posts: 138
09-11-2005 23:41
What is it that you're trying to have the script do?

If you're trying to go from one picture to the next, cycling through just 2 images, you'd be better off using llOffsetTexture. llSetTextureAnim is a property of the prim, so once turned on, it must be turned off to stop. Just resetting the script won't turn off the animation.
Julian Fate
80's Pop Star
Join date: 19 Oct 2003
Posts: 1,020
09-11-2005 23:51
A straight copy and paste of your code works for me though I used 6 seconds rather than 120 for testing purposes. Are you sure the land you are on allows scripts to execute, and have you made sure the "Running" box is checked in your script window?

Here is a piece of code that might be helpful in testing. Put it inside your timer() event.
CODE
llOwnerSay("Time's up.");

Also, unrelated to your problem, you may want to stop your timer after the animation starts to avoid it unnecessarily restarting the texture animation. It probably won't be visually obvious but it is more work for the server and people's computers. Try this:
CODE
timer(){
llOwnerSay("Time's up."); // Comment this out if you don't need it.
llSetTextureAnim(ANIM_ON | PING_PONG | LOOP, ALL_SIDES, 2, 2, 0, 0, 2.0);
llSetTimerEvent(0.0);
}
Mustelid Carnot
Made from quality ferrets
Join date: 7 Sep 2005
Posts: 106
09-12-2005 08:16
Okay, what I am trying to do is have my texture (a 4 screen animation of a blink) blink infrequently. So I want to to animate, (1234-4321), STOP animating, and wait until the timer trigs it again.
Mustelid Carnot
Made from quality ferrets
Join date: 7 Sep 2005
Posts: 106
09-12-2005 08:18
From: FireEyes Fauna
What is it that you're trying to have the script do?

If you're trying to go from one picture to the next, cycling through just 2 images, you'd be better off using llOffsetTexture. llSetTextureAnim is a property of the prim, so once turned on, it must be turned off to stop. Just resetting the script won't turn off the animation.


How do you turn it off?
Can I use llOffsetTexture to cycle through my four cels instead? would that work? And if so, can I time THAT so it does it infrequently?
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
09-12-2005 12:57
CODE

//Blink Script
//Copyright (C) 2005, Strife Onizuka
//GNU General Public License
//http://www.gnu.org/licenses/gpl.txt

//Length in seconds it takes to blink.
float blinklength = 1.0;
//Start frame
integer startFrame = 0;

// Frame numbering matrix
// +---+---+
// | 0 | 1 |
// +---+---+
// | 2 | 3 |
// +---+---+

integer xFrames = 2;
integer yFrames = 2;

integer setMode()
{//don't foul with this unless you really really want to
return mode = ANIM_ON
// | REVERSE //If the eyes in your texture start closed, uncomment this
| PING_PONG;
}

float blinkSpeed;
integer currentFrame;
integer mode;
integer status;

blink()
{
tAnim(mode);
}

integer tAnim(integer a)
{//returns the number of frames
integer b;
if(status&1)
llSetTextureAnim(0, ALL_SIDES, 0, 0, 0, 0, 0);
if(a)
{
llSetTextureAnim(a, ALL_SIDES, xFrames, yFrames, currentFrame,
b = xFrames * yFrames - currentFrame + startFrame, blinkSpeed);
if(a & PING_PONG)
b = b * 2 - 1;
status = status | 1;
}
else
status = status & -2; //-2 = ~1
return b;
}

setFrame(integer a)
{//pass this a frame number you would want the script to play
integer numberFrames = xFrames * yFrames;
a = a % numberFrames;
if(a<0)
a += numberFrames;
currentFrame = ((a - startFrame) % numberFrames) + startFrame;
if(currentFrame<0)
currentFrame += numberFrames;
tAnim(FALSE);
llOffsetTexture(((a%xFrames) - ((xFrames - 1)/2.0))/xFrames,
(((yFrames - 1)/2.0) - (a/xFrames))/yFrames, ALL_SIDES);
}

default
{
state_entry()
{
if(setMode() & PING_PONG)
blinkSpeed = ((xFrames * yFrames * 2.0) - 1) / blinklength;
else
blinkSpeed = (xFrames * yFrames) / blinklength;
llScaleTexture(1.0/xFrames,1.0/yFrames,ALL_SIDES);
setFrame(startFrame);
tAnim(0);

llSetTimerEvent(120.0);
}

timer()
{
blink();
}

}
_____________________
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
Mustelid Carnot
Made from quality ferrets
Join date: 7 Sep 2005
Posts: 106
09-12-2005 13:07
Oh good heavens! Thank you! That's a hell of a script!
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
09-12-2005 14:18
llSetTextureAnim should be better documented, it's one of the most annoying functions to figure out.

The functions will let you add new features to the script (without having to figure out how to code them), for example you could code a tired mode activated by a listen (to do that you would just call setFrame(2 + startFrame);blink(); ).

Oh and there is a little bug ^^; i'll fix that now.

EDIT: Fixed
_____________________
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