Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: imagazzell on Thu 11/11/2021 06:32:43

Title: [SOLVED] Randomized idle blinking
Post by: imagazzell on Thu 11/11/2021 06:32:43
Hi folks,

So I'm trying to have my player character blink at random intervals while idle, and I'm having a little trouble wrapping my brain around how to get it to work right. (I know not to use the Blinking View, as I'm not doing a Sierra-style game.)

I have a view (#4) with a single blink animation. Then, in my global script, I tried this:

Code (ags) Select

function repeatedly_execute()
{
  int i;
  i = Random(10);
  cEgo.SetIdleView(4, i);
}


But that's not working as desired. The animation appears to be zipping by more rapidly than if I left it as an ordinary, evenly spaced idle view, and is also occurring way too frequently. I imagine it's got something to do with my randomized SetIdleView delay (which I assumed, from my understanding of the manual description, would be the delay between each playing of the view), but I'm unsure as to what exactly the problem is, and how to fix it.

Any insights (or tips on how to better achieve this in general)?
Title: Re: Randomized idle blinking
Post by: Babar on Thu 11/11/2021 07:51:23
The problem here is that you have this function in repeatedly_execute(), which runs every gameloop, which is by default 40 times a second. So 40 times a second you are resetting the character's idle view with a different idle delay.

One possible solution (I can't verify it as I don't have AGS available just now) is that instead of setting the idleview every game loop, you can couch it inside a check inside the repeatedly_execute, e.g.

Code (ags) Select

if (cEgo.View==4)
{
  cEgo.SetIdleView(4, Random(10)+1);
}


This way the delay will reset only after the player has already blinked.
Title: Re: Randomized idle blinking
Post by: Khris on Thu 11/11/2021 09:53:45
This approach will indeed work but it also needs a short delay. The following did work for me:

Code (ags) Select
  // inside repeatedly_execute
  if (cEgo.View == ROGERIDLE) SetTimer(1, 10); // delay resetting the idle view so it has a chance to play
  if (IsTimerExpired(1)) cEgo.SetIdleView(ROGERIDLE, Random(5)+5); // 5-10 seconds
Title: Re: Randomized idle blinking
Post by: imagazzell on Thu 11/11/2021 18:46:59
Thanks for the suggestions, guys!

Khris, your method did the trick. I also added the cEgo.SetIdleView(ROGERIDLE, Random(5)+5); line to the game_start function, so that the blinking can start right away once the character is idle, rather than after the default idle view start delay. Do you see any potential problems in doing that?


On another note, what would be a good way to implement other idle animations, such as the character tapping their foot, initiated amongst the blinking animations?
Title: Re: Randomized idle blinking
Post by: Khris on Thu 11/11/2021 23:27:10
Calling the function in game start shouldn't cause any issues, no.

You mean like the character is both tapping their foot and blinking, independently? That's much harder because AGS doesn't really support animating the head and body separately the way the Lucasfilm games did. It's possible somehow but can't be achieved with just a few lines of code unfortunately.
Title: Re: Randomized idle blinking
Post by: imagazzell on Thu 11/11/2021 23:46:42
Quote from: Khris on Thu 11/11/2021 23:27:10
You mean like the character is both tapping their foot and blinking, independently? That's much harder because AGS doesn't really support animating the head and body separately the way the Lucasfilm games did. It's possible somehow but can't be achieved with just a few lines of code unfortunately.
The animations don't have to occur independently. The foot tapping (or whatever else) can happen between blinking animations by itself, either at specific intervals or randomly too. Thoughts on how best to approach that? Another timer within the function we already created, perhaps?


I've also noticed a strange issue with the blinking animations. Do idle views not honor diagonal loops like walking views do? The wrong blink loops seem to be firing after my character has walked in a diagonal direction and gone idle. The four primary directions seem to be using the correct loops.
Title: Re: Randomized idle blinking
Post by: Khris on Fri 12/11/2021 08:22:30
That sounds like a bug.

For a second idle view you can use
Code (ags) Select
  cEgo.SetIdleView(ROGERIDLE + Random(1) * (ROGERLEGIDLE - ROGERIDLE), Random(5)+5);
in that case, this will play either view randomly.
Title: Re: Randomized idle blinking
Post by: Cassiebsg on Fri 12/11/2021 16:05:33
Make sure that all the sprites are in the correct loop.
On my latest game I had a "bug" that was driving me nuts, as my character was facing the wrong way on a single view/loop, and I couldn't figure out why. After several days trying to fix it, I looked at the sprites and noticed that I had a single wrong sprite in that exact loop.  (roll)

Not saying it's your case, but just make sure.  ;)
Title: Re: Randomized idle blinking
Post by: imagazzell on Sat 13/11/2021 03:10:00
Quote from: Khris on Fri 12/11/2021 08:22:30
For a second idle view you can use
Code (ags) Select
  cEgo.SetIdleView(ROGERIDLE + Random(1) * (ROGERLEGIDLE - ROGERIDLE), Random(5)+5);
in that case, this will play either view randomly.
Thanks, Khris! And if I wanted to have the foot-tapping happen less frequently than the blinking (say, between every four blinking animations)? Maybe just set a counter within the randomized blinking code that would trigger the foot-tapping instead? Seems fairly straightforward.

Quote from: Cassiebsg on Fri 12/11/2021 16:05:33
Make sure that all the sprites are in the correct loop.
On my latest game I had a "bug" that was driving me nuts, as my character was facing the wrong way on a single view/loop, and I couldn't figure out why. After several days trying to fix it, I looked at the sprites and noticed that I had a single wrong sprite in that exact loop.  (roll)

Not saying it's your case, but just make sure.  ;)
Thank you for the suggestion, Cassiebsg, but I was sure to double and triple-check and re-assign the sprites again, but the error still occurred. I'm thinking it's either something else in my scripts throwing it off, the idle view not honoring diagonal directions, or indeed a bug, as Khris said.