Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HandsFree on Mon 25/01/2021 23:54:52

Title: Why does this animation play 3 times?
Post by: HandsFree on Mon 25/01/2021 23:54:52
Hi,

I'm stumped here. The animation plays 3 times and then stops.Since the x-coordinate for the dog is set back it's supposed to play one time only.
Code (ags) Select

function room_RepExec()
{
  if (cDog.x<=195) {
    player.Walk(100,  262, eBlock, eAnywhere);
    player.FaceLocation(player.x+1, player.y);
    player.x+=10;
    cDog.Transparency=100;
    cDog.x = 288;
    cDog.y = 280;
    player.Animate(36, 3, eOnce, eBlock);
  }
}


Any ideas?
thanks
Title: Re: Why does this animation play 3 times?
Post by: Khris on Tue 26/01/2021 00:04:52
When you want to animate a character, it's best to use a separate view and call  player.LockView(PLAYER_ANIMATIONS);  first, otherwise you may get unexpected results.
(PLAYER_ANIMATIONS is an example name for the view here)
Title: Re: Why does this animation play 3 times?
Post by: HandsFree on Tue 26/01/2021 00:17:21
Ai, this is a big game and I'm just helping out. Many animations have been placed in the normal view (it has 43 loops) and they all play out well. It's just this one (so far) that behaves weird. Placing them elsewhere will have quite some impact.
Title: Re: Why does this animation play 3 times?
Post by: Khris on Tue 26/01/2021 00:21:18
https://en.wikipedia.org/wiki/Technical_debt ;)

Just kidding, but I'd definitely try copying the animation to a new view and testing it. If the issue doesn't go away, the problem is indeed elsewhere.
Title: Re: Why does this animation play 3 times?
Post by: HandsFree on Tue 26/01/2021 00:38:36
If I do this

function room_RepExec()
{
  if (cDog.x<=195) {
    player.Walk(100,  262, eBlock, eAnywhere);
    player.FaceLocation(player.x+1, player.y);
    player.x+=10;
    cDog.Transparency=100;
    cDog.x = 288;
    cDog.y = 280;
    player.LockView(DOG_ATTACK);
    player.Animate(0, 3, eOnce, eBlock);
    player.UnlockView();
  }
}

I see the animation unlocking and restarting three times.

If I do this:

function room_RepExec()
{
  if (cDog.x<=195) {
    player.Walk(100,  262, eBlock, eAnywhere);
    player.FaceLocation(player.x+1, player.y);
    player.x+=10;
    cDog.Transparency=100;
    cDog.x = 288;
    cDog.y = 280;
    player.LockView(DOG_ATTACK);
    player.Animate(0, 3, eOnce, eBlock);
    player.UnlockView();
    ShowDeathGui(eDeathDogAttack);
  }
}

The death gui coms up after one animation. But when I click it away it gives an error at player.Walk(100,  262, eBlock, eAnywhere); because there's no loop one.
Apparently it is still in the dog_attack view, and the condition  if (cDog.x<=195) appears ither not checked or still true.

edit: oops, I made a typing error in unlockview. Now that error doesn't happen, but the game locks up when the gui is displayed, I'm assuming because it wants to play the animation 2 more times.
Title: Re: Why does this animation play 3 times?
Post by: Crimson Wizard on Tue 26/01/2021 00:44:49
Can you display dog coordinates before "if"?
The whole thing is rather strange.

Quote
player.FaceLocation(player.x+1, player.y);

By the way, there's Character.FaceDirection function which can be used to face explicit direction.
Title: Re: Why does this animation play 3 times?
Post by: HandsFree on Tue 26/01/2021 00:49:36
In room_Load() there's
cDog.ChangeRoom(49, 288, 280);

And in room_AfterFadeIn() there's
Code (ags) Select

if (dog_bone==false) {
    EnableRegions();
    RemoveWalkableArea(5);
    Display("Watch out! A VERY unfriendly dog rushes toward you!");
    mouse.SetPosition(300, 15);
    cDog.Walk(120, 275, eNoBlock, eAnywhere);
  }
Title: Re: Why does this animation play 3 times?
Post by: Khris on Tue 26/01/2021 08:33:43
So the death GUI blocks the game until you close it, correct?
Is it possible that closing the GUI reloads the room? And thereby resets the dog's position?

What I'd do at this point is put a debug label on a permanently visible GUI and update its text with the dog's position in repeatedly_execute_always(), then set the game speed to 5 or so.
Try to determine why the coordinate check doesn't prevent a second animation. Also, why does it happen exactly three times?  Really weird.
Sounds more and more like some global code is interfering.
Title: Re: Why does this animation play 3 times?
Post by: HandsFree on Tue 26/01/2021 14:45:22
No, the death gui blocks the game permanently. Clicking it should make it close, but that doesn't happen in this situation.
I'll try the debug label later.
Title: Re: Why does this animation play 3 times?
Post by: Cassiebsg on Tue 26/01/2021 16:44:33
Can you try and change cDog.Transparency=100; to some other value? Or just // it.
Title: Re: Why does this animation play 3 times?
Post by: HandsFree on Tue 26/01/2021 17:21:06
Well, I still don't understand how this plays out exactly, but indeed disabling the transparency and lowering the gamespeed shows that the dog was not sent back to x=288.

What appears to be the problem is the statement in room_AfterFadeIn(): cDog.Walk(120, 275, eNoBlock, eAnywhere);
In repexec the dog should be sent back when it's at x=195, but it looks like the instruction to walk to x=120 takes precedence. Is that possible?
It seems to be fixed if I set the statement in afterfadein to cDog.Walk(192, 275, eNoBlock, eAnywhere);

So it looks like my problem is solved, but if anyone understands what was really happening here I'd love to know. ;)

Thanks
Title: Re: Why does this animation play 3 times?
Post by: Khris on Wed 27/01/2021 00:50:59
Looks like manually changing the dog's x position doesn't interfere with the non-blocking walk, AGS just keeps on trucking.
You can also call  cDog.StopWalking()  instead.