But Jestermon, what if a idle animation is used?
Yes, you have a good point, since the character will have more than one animation, and you don't want to stop the "idle".
Edit: To control any animation set with script, here is the recipe.
An animation set can have any number of frames, but to the engine, the first frame in the animation time is always 0, and the last time in the animation is always 1.
Using a timer. you can set the "Animation Time" eg. OUT_22 to the decimal value of the time you need between 0 and 1, and in that way you can set which animation frame must be used in the game frame.
So to play a particular animation only once, you can have a function to step through the animation frames as needed. toggle the function on/off with some boolean.variable.
A tricky task, but not too difficult.
//By using the animation time, (which is really the current frame)
//One can control the animation by selecting the correct frame
//and simulating the animation with script
float numFrames = 56;
float currentFrame = 0;
int THING = OBJ_0;
int timer = 0;
int delay = 20;
string S;
bool ANIMATE = false;
///-------------------------------------------------------------------------
void SetFrame()
{
if(!ANIMATE){
OUT_0 = 1/numFrames*currentFrame*2.3;
OUT_1 = 0;
}else{
OUT_1 = 0.1;
}
}
///-------------------------------------------------------------------------
void Main()
{
if(timer < delay) timer++;
if(timer == delay){
if (iKeyDown(iKeyCode("DIK_UP"))){
ANIMATE = !ANIMATE;
timer = 0;
}
}
if (iKeyDown(iKeyCode("DIK_LEFT"))){
currentFrame-=0.1;
if(currentFrame < 0) currentFrame = numFrames-1;
}
if (iKeyDown(iKeyCode("DIK_RIGHT"))){
currentFrame+=0.1;
if(currentFrame >numFrames-1) currentFrame = 0;
}
SetFrame();
iObjectTextSet(OBJ_22,S="Frame #"+IN_1);
}