Author Topic: Randomized idle blinking  (Read 354 times)

Randomized idle blinking
« on: 11 Nov 2021, 06:32 »
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: Adventure Game Studio
  1. function repeatedly_execute()
  2. {
  3.   int i;
  4.   i = Random(10);
  5.   cEgo.SetIdleView(4, i);
  6. }

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)?

Babar

  • Creator, Mutator and Defecator
    • I can help with proof reading
    • I can help with scripting
    • I can help with story design
    • I can help with translating
    • Babar worked on one or more games that won an AGS Award!
    •  
    • Babar worked on one or more games that was nominated for an AGS Award!
Re: Randomized idle blinking
« Reply #1 on: 11 Nov 2021, 07:51 »
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: Adventure Game Studio
  1. if (cEgo.View==4)
  2. {
  3.   cEgo.SetIdleView(4, Random(10)+1);
  4. }
  5.  

This way the delay will reset only after the player has already blinked.
« Last Edit: 11 Nov 2021, 07:58 by Babar »
The ultimate Professional Amateur

Now, with his very own game: Alien Time Zone

Re: Randomized idle blinking
« Reply #2 on: 11 Nov 2021, 09:53 »
This approach will indeed work but it also needs a short delay. The following did work for me:

Code: Adventure Game Studio
  1.   // inside repeatedly_execute
  2.   if (cEgo.View == ROGERIDLE) SetTimer(1, 10); // delay resetting the idle view so it has a chance to play
  3.   if (IsTimerExpired(1)) cEgo.SetIdleView(ROGERIDLE, Random(5)+5); // 5-10 seconds

Re: Randomized idle blinking
« Reply #3 on: 11 Nov 2021, 18:46 »
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?

Re: Randomized idle blinking
« Reply #4 on: 11 Nov 2021, 23:27 »
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.

Re: Randomized idle blinking
« Reply #5 on: 11 Nov 2021, 23:46 »
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.

Re: Randomized idle blinking
« Reply #6 on: 12 Nov 2021, 08:22 »
That sounds like a bug.

For a second idle view you can use
Code: Adventure Game Studio
  1.   cEgo.SetIdleView(ROGERIDLE + Random(1) * (ROGERLEGIDLE - ROGERIDLE), Random(5)+5);
in that case, this will play either view randomly.

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Randomized idle blinking
« Reply #7 on: 12 Nov 2021, 16:05 »
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.  ;)
There are those who believe that life here began out there...

Re: Randomized idle blinking
« Reply #8 on: 13 Nov 2021, 03:10 »
For a second idle view you can use
Code: Adventure Game Studio
  1.   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.

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.