Time based animation change

O Ilusionista

Captain 100K
Hi.
I want to use a looped animation that, once the elapsed time reaches X, the entity would change to another attack, but something is wrong (crashing or not working).

At frame 0, I get the elapsed_time and after it reaches elapsed_time+1000, it should go to attack1, but it crashes. If I remove the frame==0 part, it doesn't crashes but

This is my code
Code:
	@script
	if (frame==0)
	{
	   void self = getlocalvar("self");
	   int time = openborvariant("elapsed_time");
	}
	if (time==time+1000)
	{
	performattack(self, openborconstant("ANI_ATTACK1"));
	}
	@end_script
Script compile error in 'animationscript': time line 47, column 8

What I am doing wrong?
 
Clearly, you only declare time inside if( frame==0) { } not outside of it, therefore time is unknown to scripts outside

Even if it does work, the script only acquire elapsed time once (at start of animation) while you need to acquire another elapsed time i.e current one for comparison

Anyways, it's best to use entity variable for this. First, acquire starting time (elapsed time) in first frame then store it in an entity variable.
Then in looping frames like in IDLE animation, acquire current elapsed time and compare it with the stored value.
I usually do first step in different animation but I'll modify script for your purpose :) :

anim idle
@script
    void self = getlocalvar("self");
    int Summon = getentityvar(self, 1);

    if(frame==0){
      setentityvar(self, 1, openborvariant("elapsed_time"));
    }
    if(Summon <= openborvariant("elapsed_time") - 1000){
      setentityvar(self, 1, NULL());
      performattack(self,openborconstant("ANI_ATTACK1"));
    }
@end_script
loop 1 2 4 # example of looping which doesn't play first frame
...

HTH
 
Trying to set time function like command but does not work

Code:
void time (int t, void ani){
	// Changes anim pased x time
	void self = getlocalvar("self");
	int Otime = openborvariant("elapsed_time");
	
	if (Otime==Otime+t){
		changeentityproperty(self, "animation", openborconstant(ani));
	}
}

Anyone help?
 
It won't work that way, because its an animationscript.
When you call that function, its valid for that frame only (unless you use it on a @script loop) so the 0time+t won't never evaluates
 
This:

Code:
Otime==Otime+t

is impossible statement unless t = 0

Remember that if you want to make time based animation change or similar function, you MUST acquire elapsed time in 2 different times
First, you must acquire it in starting time (define it yourself). Since the elapsed time will change over time, you need to store that in a variable. That's why I stored it in an entity variable
Second, acquire it in animation where you assume time has elapsed long enough for animation change

In above example, I do the 1st step in first frame of IDLE animation while doing the 2nd step in remaining frames of IDLE animation
Gained values from 1st step and 2nd step are compared to each other. If time has elapsed long enough then do animation change

As for making a function version of this, I can imagine some cases where it might be useful but if you need strict timing or small time tolerance, I recommend using animation script as shown above
 
Back
Top Bottom