Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: isatche on Sat 26/09/2020 09:37:46

Title: [SOLVED] Weird problem. eOnce plays twice
Post by: isatche on Sat 26/09/2020 09:37:46
Hello,
I want my character to take a hit and tumble while flying backwards.
The problem is, he tumbles while going back but tumbles again when he reaches the destination and then stops.
It annoys me to no end.

Here is the code:
Code (ags) Select

//Grumpy rams Starman
oGrumpy.SetView(22);
oGrumpy.Animate(0, 1, eOnce, eNoBlock);
oGrumpy.Move(420, 300, 1, eBlock, eAnywhere);
oGrumpy.Graphic = 27;


// Staman Tumbles
cStarman.LockView(21); //tumble animation

cStarman.Animate(0, 3, eOnce, eNoBlock);

cStarman.Move(350, 300, eBlock, eAnywhere);



Any ideas please?
Thank you!
Title: Re: Weird problem. eOnce plays twice
Post by: Matti on Sat 26/09/2020 10:14:57
You need to use eBlock when calling the animation, otherwise the animation and Move-commands will be called at the same time.
Title: Re: Weird problem. eOnce plays twice
Post by: isatche on Sat 26/09/2020 12:17:03
The animation and the move should be at the same time since he tumbles while moving.
The problem is, animation plays while moving and then plays again when the moving stops.
Title: Re: Weird problem. eOnce plays twice
Post by: Slasher on Sat 26/09/2020 12:37:46
Where have you put the script?

Are you using collide script?
Title: Re: Weird problem. eOnce plays twice
Post by: isatche on Sat 26/09/2020 18:08:14
Umm.. I am not sure what is a collide script?
The script is in a room.

Here is the whole thing if it helps...

Code (ags) Select


function room_FirstLoad()
{
  cWildling.SetAsPlayer();

oLanding.Visible = false;

oGrumpy.SetView(17);
oGrumpy.Animate(0, 3, eRepeat, eNoBlock); // Idle animation

StartCutscene(1);

cWildling.SpeechView = 11;
cWildling.Say("Here you are!");
cWildling.Walk (527, 305, eBlock);
cWildling.Say("...");
cWildling.SpeechView = 18;
cWildling.Say("WHAT. IS. THAT?");

oLanding.Visible = true;
oLanding.SetView(16);
oLanding.Animate(0, 3, eOnce, eNoBlock);
oLanding.Move(344, 295, 1, eBlock, eAnywhere);

cWildling.Say("...");

oLanding.Graphic = 152;
cStarman.Transparency = 0;

cWildling.Say("...");


cStarman.Walk(415, 301, eBlock, eAnywhere);
cStarman.Say("Hello, I come in p...");
cWildling.Say("AAAAH!");

//Grumpy rams Starman
oGrumpy.SetView(22);
oGrumpy.Animate(0, 1, eOnce, eNoBlock);
oGrumpy.Move(420, 300, 1, eBlock, eAnywhere);

oGrumpy.Graphic = 27;

// Staman Tumbles
cStarman.LockView(21);

cStarman.Animate(0, 3, eOnce, eNoBlock);

cStarman.Move(350, 300, eBlock, eAnywhere);



cWildling.Say("GRUMPY! NOoo...");
oGrumpy.SetView(23);//Grumpy runs away
oGrumpy.Animate(0, 1, eRepeat, eNoBlock);
oGrumpy.Move(626, 228, 1, eBlock);
oGrumpy.Visible = false;

visible = 1;
cWildling.Say("...");
cWildling.Walk (480, 305, eBlock);
cWildling.Say("Is he alive?");

EndCutscene();
}


Title: Re: Weird problem. eOnce plays twice
Post by: morganw on Sat 26/09/2020 19:50:58
Do you just mean this part plays the animation twice?
Code (ags) Select
// Staman Tumbles
cStarman.LockView(21);

cStarman.Animate(0, 3, eOnce, eNoBlock);

cStarman.Move(350, 300, eBlock, eAnywhere);
Title: Re: Weird problem. eOnce plays twice
Post by: isatche on Sun 27/09/2020 07:23:31
Correct.
Once when it's supposed to, while moving.
And it repeats the animation once more when moving stops.

I'll try and take a screen-grab later today so you can see what it looks like.
I might go around and use object instead of the character, but I am still curious why is it happening.
Title: Re: Weird problem. eOnce plays twice
Post by: Slasher on Sun 27/09/2020 07:37:03
You could double check if 'play next loop' in the view 21 is ticked..
Title: Re: Weird problem. eOnce plays twice
Post by: isatche on Sun 27/09/2020 07:45:54
There is only one loop in that view and "run the next loop..." is grayed out and unchecked.
Title: Re: Weird problem. eOnce plays twice
Post by: Snarky on Sun 27/09/2020 08:53:04
First, you seem to be missing an UnlockView after the animation, though I'm not sure whether SetView takes care of it. In any case, I would add that for consistency.

Then I'd start by commenting out the rest of the cut-scene. Does it still happen?
Then try commenting out the Move, and change the Animate to blocking. Does it still happen?
Then try commenting out the parts before the Animate. Does it still happen?

If you're left with just that one command and it still plays the animation twice, the problem must not be in the script.
Title: Re: Weird problem. eOnce plays twice
Post by: isatche on Sun 27/09/2020 09:15:33
Quoteyou seem to be missing an UnlockView after the animation
I want him to stay on the last frame until the player takes the action. He is knocked out and the player needs to revive him.

QuoteThen I'd start by commenting out the rest of the cut-scene. Does it still happen?
- Yes

QuoteThen try commenting out the Move, and change the Animate to blocking. Does it still happen?
The problem is, it repeats after the move is done. When I comment out the move, it plays once as it should be.
When I block the animation, it plays in one spot, then move while on last frame, then at the end of move it ends on the first frame of the animation and stays there?!

QuoteThen try commenting out the parts before the Animate. Does it still happen?
Yes, it does.

Here is the video: https://youtu.be/UBVxMzyOzGE
The problem is around 17sec mark.
Title: Re: Weird problem. eOnce plays twice
Post by: isatche on Sun 27/09/2020 09:18:50
Here is the view 21
https://i.imgur.com/KhekBRj.png
Title: Re: Weird problem. eOnce plays twice
Post by: Slasher on Sun 27/09/2020 09:58:17
Because it is quite quick could you not try

Code (ags) Select

cStarman.LockView(21);
cStarman.Move(350, 300, eNoBlock, eAnywhere)
cStarman.Animate(0, 3, eOnce, eBlock);
cStarman.Move(350, 300, eNoBlock, eAnywhere)
Title: Re: Weird problem. eOnce plays twice
Post by: isatche on Sun 27/09/2020 10:13:29
Hi,
thanks, but it doesn't work. he tumbles in place, then slides back on his belly and freezes at first frame in the end. It made me giggle so it's a plus :)
I'm starting to thing that something's wrong with my version of AGS (3.4.3) or I made some stupid mistake somewhere else in a script to make it trigger like this or something.
It just happens when I do this with character. If I do it with an object, it works fine. So I will replace the character with the object and at one point when the cutscene is done, I will switch back between an object and a character.
Title: Re: Weird problem. eOnce plays twice
Post by: Slasher on Sun 27/09/2020 10:18:50
Could be a scripting confliction somewhere..

Tumble should only loop once...

It's still in Lockview...
Title: Re: Weird problem. eOnce plays twice
Post by: Cassiebsg on Sun 27/09/2020 11:42:45
Just a thought, but could you replace the animate+move with a walk command instead? Since walk moves and plays the animation.

Edit: and/or split the animation in 2. Use the tumbling as loop 0 and flat on the floor as loop 1, then run loop0 and end at loop 1.
Title: Re: Weird problem. eOnce plays twice
Post by: Crimson Wizard on Sun 27/09/2020 12:17:31
You guys....

I just made a test game with this loop and only 3 above script lines, and this behavior reproduces (AGS 3.5.0).


If you slow animation down (set delay 5 etc), you can clearly see that animation begins playing, but as soon as character stops it is overriden and starts playing anew.

Can't remember for certain, but maybe we heard about this issue before? (I mean, this seem like something easily noticable...)   and so far it looks like a serious mistake in the engine.


UPDATE: same happens if you do non-blocking movement.

UPDATE2: If you make moving distance long enough for the first animation to complete, then upon stopping moving it does not play full anim again but resets loop to frame 0 and stays there.
Title: Re: Weird problem. eOnce plays twice
Post by: Crimson Wizard on Sun 27/09/2020 12:43:10
@isatche

This workaround is best that I could come with after experiments. It replaces Move command with manual coordinate change. This should work because you use eAnywhere, so do not need pathfinding here:

Code (ags) Select

       player.LockView(21);
       player.Animate(0, 3, eOnce, eNoBlock);
       while (player.x > 350)
       {
           player.x -= 5; // change 5 to the wanted speed
           Wait(1);
       }



PS. Not relevant to the problem at hand, but each View you create adds a script constant identical to the view's name in caps. E.g. if you create View called vTumble there will be script constant VTUMBLE equal to the View's ID.
Then you can use this constant instead of bare numbers, like:
Code (ags) Select

player.LockView(VTUMBLE);

this may make it easier to understand your code in case you forget something.
Title: Re: Weird problem. eOnce plays twice
Post by: Snarky on Sun 27/09/2020 12:50:08
An alternative solution in this case would be to just… let the animation play twice, because it looks pretty cool. :P :-D

Good job confirming it's an engine bug, CW! Yes, once the problem was narrowed down it did start to sound vaguely familiar, but I wasn't able to dig up a previous report of the bug. Edit: The same problem was previously reported here (https://www.adventuregamestudio.co.uk/forums/index.php?topic=53977.msg636544419), but the cause was not found.

(When fixing this bug, maybe take a look at this one (https://www.adventuregamestudio.co.uk/forums/index.php?topic=57777) too, if it hasn't already been addressed.)
Title: Re: Weird problem. eOnce plays twice
Post by: Crimson Wizard on Sun 27/09/2020 12:59:37
There's also something similar, but idk if related or not: https://github.com/adventuregamestudio/ags/issues/935
I will open a separate ticket just in case. https://github.com/adventuregamestudio/ags/issues/1123
Title: Re: Weird problem. eOnce plays twice
Post by: isatche on Sun 27/09/2020 15:43:46
Thank you all very much!

The workaround works great.
How should I tag the post now? Is it solved or?
Title: Re: Weird problem. eOnce plays twice
Post by: morganw on Sun 27/09/2020 17:09:01
Just to note, I thought it looked pretty good with the extra animation (as shown in the YouTube video).
Title: Re: Weird problem. eOnce plays twice
Post by: Snarky on Sun 27/09/2020 17:51:05
Yeah, I also liked it.

And yes, knowing that it is due to an engine bug, and having a workaround until it gets fixed, I think we would consider the question solved.
Title: Re: Weird problem. eOnce plays twice
Post by: isatche on Sun 27/09/2020 18:52:13
Quote from: morganw on Sun 27/09/2020 17:09:01
Just to note, I thought it looked pretty good with the extra animation (as shown in the YouTube video).
Since both you and Snarky had the same comment, I'll include one extra tumble. But on my terms, because I want to, not because of the bug :D
Thank you all again!
Title: Re: [SOLVED] Weird problem. eOnce plays twice
Post by: Crimson Wizard on Sun 04/06/2023 19:57:33
Quote from: Crimson Wizard on Sun 27/09/2020 12:59:37I will open a separate ticket just in case. https://github.com/adventuregamestudio/ags/issues/1123

This should have been done back in 2020, because the fix appeared to be rather trivial. But now it's fixed in 3.6.0 Patch2.