Starting an animation after .SetAsPlayer (SOLVED)

Started by khnum, Sat 07/04/2007 12:18:06

Previous topic - Next topic

khnum

So, i' making a gui to switch between different characters, and when you click on the image of the character you want to switch to, an animation starts; anyway, if the character is in the same room, there are no problems, but if the player is in another room, the room changes after the animation (and i want it to start after the room change). Since setAsPlayer waits for the entire function to finish before switching, what can i do?

Scorpiorus

You can work around it by setting a flag variable instead of starting an animation on clicking the image.
Then you can check for that flag in the repeatedly_execute() event function of the main global script and run animation from there:

At the top of the main global script:
Code: ags

bool bRunAnimation = false;



on clicking the image:
Code: ags

cSomeCharacter.SetAsPlayer();
bRunAnimation = true;


repeatedly_execute()
Code: ags

if ( bRunAnimation == true )
{
    < start animation here >

    bRunAnimation = false; // to avoid starting it repeatedly
}


Scorpiorus

You are welcome :)

Ah and one thing to add: if you were running different animations for different images, you can reproduce it with if-else within repeatedly_execute taking a current value of the player variable as condition to check for:

repeatedly_execute()
Code: ags

if ( bRunAnimation == true )
{
    if      (player == cEgo1)  < start cEgo1-specific animation here >;
    else if (player == cEgo2)  < start cEgo2-specific animation here >;
    else if (player == cEgo3)  < start cEgo3-specific animation here >;

    bRunAnimation = false; // to avoid starting it repeatedly
}

SMF spam blocked by CleanTalk