Solved change "loop" value from script

Question that is answered or resolved.

dcelso

Member
Hi,
I'm trying to do a spawn animation doing that the player appears in the screen walking I have put loop =1 and the images of the walking.
Now I want to put that value to 0 when the player does 10 steps.
I've found this function setanimationproperty, but I dont have any help that how to use it.
 
Solution
I'm trying to do a spawn animation doing that the player appears in the screen walking I have put loop =1 and the images of the walking.
Now I want to put that value to 0 when the player does 10 steps.

You can do as Damon suggested either with copypaste walk animation OR use looper function to loop the animation couple times.
This is the function to do that:
Code:
void looper(int Frame, int Limit)
{// Loops current animation
    void self = getlocalvar("self");
    void loop = getlocalvar("Loop" + self);

    if(loop==NULL()){ // Localvar empty?
      setlocalvar("Loop" + self, 0);
      loop = 0;
    }
  
    if(loop < Limit){ // loops reach limit?
      setlocalvar("Loop" + self, loop+1); // Increment number of loops...
Hi,
I'm trying to do a spawn animation doing that the player appears in the screen walking I have put loop =1 and the images of the walking.
Now I want to put that value to 0 when the player does 10 steps.
I've found this function setanimationproperty, but I dont have any help that how to use it.

That's not really what that function does. You can run the 10 steps with script, but honestly, this is one case where it's probably simpler to just hard-code the 10 steps into your spawn animation.


DC
 
That's not really what that function does. You can run the 10 steps with script, but honestly, this is one case where it's probably simpler to just hard-code the 10 steps into your spawn animation.


DC
ahh, :D. ok thank.
and is there any function to finish the animation?
I've tried
@script
if (frame <30){
break;
}
@end_script
with return, and exit tpp

but the code continues doing the loop. :'(
 
ahh, :D. ok thank.
and is there any function to finish the animation?
I've tried
@script
if (frame <30){
break;
}
@end_script
with return, and exit tpp

but the code continues doing the loop. :'(


Well the first problem is how in the world is the engine supposed to know what "frame" means? It's an undeclared variable with no context. I'm surprised the engine didn't throw an error to the log and shut down, but we'll get into that later. Unless it's for special tricks, animations don't need scripts to end. They just do.

When I say hardcoding, I mean make a non looping animation, and just copypaste the walk cycle ten times into the animation text. It's kind of brutish looking in the text, but doesn't cost any extra resources, and is super simple. Unless you are trying to do something else more advanced that you haven't mentioned, that's your best ticket.

DC
 
I'm trying to do a spawn animation doing that the player appears in the screen walking I have put loop =1 and the images of the walking.
Now I want to put that value to 0 when the player does 10 steps.

You can do as Damon suggested either with copypaste walk animation OR use looper function to loop the animation couple times.
This is the function to do that:
Code:
void looper(int Frame, int Limit)
{// Loops current animation
    void self = getlocalvar("self");
    void loop = getlocalvar("Loop" + self);

    if(loop==NULL()){ // Localvar empty?
      setlocalvar("Loop" + self, 0);
      loop = 0;
    }
  
    if(loop < Limit){ // loops reach limit?
      setlocalvar("Loop" + self, loop+1); // Increment number of loops
      updateframe(self, Frame); //Change frame
    } else if(loop==Limit){ // loops reach limit?
      setlocalvar("Loop" + self, NULL());
    }
}

Ex: @cmd looper 1 9 means entity will return to 2nd frame 9 times before resuming the animation.

OTOH maybe you want something else such as entity walks into screen and keeps walking until he/she reaches certain range from screen?
 
Solution
May be that engine does not throw an error because "frame" continues being a command reserver word.
Edited.
I have tested "frame" reserved word and works perfectly. It returns the current frame number of the current animation.
Code:
anim    spawn
    loop    1
    delay    7
    offset    350 96
  @script    
     if (frame == 15) {
      changeentityproperty(getlocalvar("self"), "animation", openborconstant("ANI_IDLE"));     
     }
  @end_script
  move 3
    frame    data/chars/test/walk000.gif
    frame    data/chars/test/walk001.gif
    frame    data/chars/test/walk002.gif
    frame    data/chars/test/walk003.gif
    frame    data/chars/test/walk004.gif
    frame    data/chars/test/walk005.gif
    frame    data/chars/test/walk006.gif
    frame    data/chars/test/walk007.gif
    frame    data/chars/test/walk008.gif
    frame    data/chars/test/walk009.gif
    frame    data/chars/test/walk000.gif
    frame    data/chars/test/walk001.gif
    frame    data/chars/test/walk002.gif
    frame    data/chars/test/walk003.gif
    frame    data/chars/test/walk004.gif
    frame    data/chars/test/walk005.gif
    frame    data/chars/test/walk006.gif
    frame    data/chars/test/walk007.gif
    frame    data/chars/test/walk008.gif
    frame    data/chars/test/walk009.gif

I`ve changed the values from 0 to 15 without any problem.
 
Last edited:
This is my solution for the spawn. It is working perferctly.
Code:
anim    spawn
    loop    1
    delay    7
    offset    350 96
  @script    
     int times = getlocalvar("times");
     if (times == NULL()){
      times = 0;
     }       
     if (frame  == 9){
       times = times +1;
       setlocalvar("times", times );              
     }
     if (times >= 2){
      changeentityproperty(getlocalvar("self"), "animation", openborconstant("ANI_FREESPECIAL4"));     
     }
  @end_script
  jumpframe 0 0 1 0
    frame    data/chars/test/walk000.gif
    frame    data/chars/test/walk001.gif
    frame    data/chars/test/walk002.gif
    frame    data/chars/test/walk003.gif
    frame    data/chars/test/walk004.gif
    frame    data/chars/test/walk005.gif
    frame    data/chars/test/walk006.gif
    frame    data/chars/test/walk007.gif
    frame    data/chars/test/walk008.gif
    frame    data/chars/test/walk009.gif
anim    freespecial4
    loop    0
    delay    1
    offset    350 96
    frame    data/chars/test/walk000.gif

Like I've not found any function to end the animation in demmand I have done a change to other aninmation without looping. I wanted to save that.
 
That's one way to do it. I recommend going to IDLE but not with change animation function but with this:
setidle(self, openborconstant("ANI_IDLE"));

The other way is to script the looping effect and cancel the looping effect if it has reached certain number of looping. That's how looper function works actually :D.
 
That's one way to do it. I recommend going to IDLE but not with change animation function but with this:
setidle(self, openborconstant("ANI_IDLE"));

The other way is to script the looping effect and cancel the looping effect if it has reached certain number of looping. That's how looper function works actually :D.
:o, That ( setidle) is that I need. Better solution. Thanks so much.
 
This is my solution for the spawn. It is working perferctly.
Code:
anim    spawn
    loop    1
    delay    7
    offset    350 96
  @script   
     int times = getlocalvar("times");
     if (times == NULL()){
      times = 0;
     }      
     if (frame  == 9){
       times = times +1;
       setlocalvar("times", times );             
     }
     if (times >= 2){
      changeentityproperty(getlocalvar("self"), "animation", openborconstant("ANI_FREESPECIAL4"));    
     }
  @end_script
  jumpframe 0 0 1 0
    frame    data/chars/test/walk000.gif
    frame    data/chars/test/walk001.gif
    frame    data/chars/test/walk002.gif
    frame    data/chars/test/walk003.gif
    frame    data/chars/test/walk004.gif
    frame    data/chars/test/walk005.gif
    frame    data/chars/test/walk006.gif
    frame    data/chars/test/walk007.gif
    frame    data/chars/test/walk008.gif
    frame    data/chars/test/walk009.gif
anim    freespecial4
    loop    0
    delay    1
    offset    350 96
    frame    data/chars/test/walk000.gif

Like I've not found any function to end the animation in demmand I have done a change to other aninmation without looping. I wanted to save that.

Nice job, but about reserved words - you really should not rely on them, because they aren't reserved for your use. They could change any time the engine is updated and break your script. The way to get current frame is to extract it using a function:

Code:
void target_entity = getlocalvar("self");
int animation_frame = getentityproperty(target_entity, "animpos");

HTH,
DC
 
Here is the valid solution for this, but I will use the looper solution ( to can reuse it for the rest of players :) )
Code:
anim    spawn
    loop    1
    delay    7
    offset    350 96
  @script    
     int times = getlocalvar("times");
     if (times == NULL()){
      times = 0;
     }       
     if ( getentityproperty( getlocalvar("self") , "animpos") == 9){
       times = times +1;
       setlocalvar("times", times );              
     }
     if (times >= 2){
      setidle(getlocalvar("self"), openborconstant("ANI_IDLE"));     
     }
  @end_script
  jumpframe 0 0 1 0
    frame    data/chars/test/walk000.gif
    frame    data/chars/test/walk001.gif
    frame    data/chars/test/walk002.gif
    frame    data/chars/test/walk003.gif
    frame    data/chars/test/walk004.gif
    frame    data/chars/test/walk005.gif
    frame    data/chars/test/walk006.gif
    frame    data/chars/test/walk007.gif
    frame    data/chars/test/walk008.gif
    frame    data/chars/test/walk009.gif
 
Back
Top Bottom