Waiting for the animation to end

Started by lafouine88, Wed 20/01/2021 20:55:42

Previous topic - Next topic

lafouine88

Hey guys.
Do you know if there is a way to wait for an animation to end without blocking the game?
For instance:
Code: ags

Player.LockView(2);
Player.Animate(1,5,eOnce,eNoBlock);
"Someway to wait for it to end"
Player.UnlockView();


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

Crimson Wizard

#1
If you just need game update running, but keep player unable to progress the game, you could try following solution:

Code: ags

Player.LockView(2);
Player.Animate(1,5,eOnce,eNoBlock);
while (Player.Animating)
{
     Wait(1); // wait minimal time to update the game in background and keep checking if it's still animating
};
Player.UnlockView();


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: ags

function repeatedly_execute()
{
    // if player is locked in View 2 and not animating anymore, then unlock the view
    if (!Player.Animating && player.View == 2)
    {
         Player.UnlockView();
    }
}


Note that in the room script "repeatedly_execute" does not work, and you have to instead use room's event.

lafouine88

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

Crimson Wizard

#3
Quote from: lafouine88 on Thu 21/01/2021 11:04:09
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.

lafouine88

OK thanks a lot for the tip. I'll try this :)

SMF spam blocked by CleanTalk