Author Topic: Waiting for the animation to end  (Read 296 times)

Waiting for the animation to end
« on: 20 Jan 2021, 20:55 »
Hey guys.
Do you know if there is a way to wait for an animation to end without blocking the game?
For instance:
Code: Adventure Game Studio
  1. Player.LockView(2);
  2. Player.Animate(1,5,eOnce,eNoBlock);
  3. "Someway to wait for it to end"
  4. Player.UnlockView();
  5.  

It's been bugging me for a while now and I kept avoiding the problem but there is maybe an easier way:)

Thanks in advance
« Last Edit: 21 Jan 2021, 00:25 by lafouine88 »

Re: Waiting for the animation to end
« Reply #1 on: 21 Jan 2021, 07:54 »
If you just need game update running, but keep player unable to progress the game, you could try following solution:

Code: Adventure Game Studio
  1. Player.LockView(2);
  2. Player.Animate(1,5,eOnce,eNoBlock);
  3. while (Player.Animating)
  4. {
  5.      Wait(1); // wait minimal time to update the game in background and keep checking if it's still animating
  6. };
  7. Player.UnlockView();
  8.  

This runs the Wait(1) in the loop until animation finishes.


If on another hand you want to simply run the animation for some time while player can continue to play the game, for that case there's repeatedly_execute and similar functions, where you test when something ended or happened. These functions runs periodically, and eventually the condition will be met.

Something like that:
Code: Adventure Game Studio
  1. function repeatedly_execute()
  2. {
  3.     // if player is locked in View 2 and not animating anymore, then unlock the view
  4.     if (!Player.Animating && player.View == 2)
  5.     {
  6.          Player.UnlockView();
  7.     }
  8. }
  9.  

Note that in the room script "repeatedly_execute" does not work, and you have to instead use room's event.
« Last Edit: 21 Jan 2021, 11:10 by Crimson Wizard »

Re: Waiting for the animation to end
« Reply #2 on: 21 Jan 2021, 11:04 »
Hey crimson, thanks for the tip. That is more or less the kind of trick I used but yours seems quite easier. It's the second one I was looking for, I don't want the player to be blocked while the animation plays. So I'll try it.

Although I did'nt understand the last part of your message. You mean that I can't do this with the repeatedly execute from the room? I don' t get why:/ Then (sorry I still suck at scripting) I must create a "repeatedly execute" function but how to apply it ?

Thanks again

Re: Waiting for the animation to end
« Reply #3 on: 21 Jan 2021, 11:13 »
Although I did'nt understand the last part of your message. You mean that I can't do this with the repeatedly execute from the room? I don' t get why:/ Then (sorry I still suck at scripting) I must create a "repeatedly execute" function but how to apply it ?

The "repeatedly_execute" and similar "repeatedly_" functions are called automatically by the engine when you put them in any script module, but not in the room script.
Rooms must have the function to be connected to event in the events table (this is same as you connect functions for "after fade in" event, or hotspot interactions, for example).

You may still call it "repeatedly_execute" if you prefer, but default name created by editor is something like "room_RepExec", don't really know why.
« Last Edit: 21 Jan 2021, 11:15 by Crimson Wizard »

Re: Waiting for the animation to end
« Reply #4 on: 21 Jan 2021, 22:00 »
OK thanks a lot for the tip. I'll try this :)