Making character animate constantly during dialog

Started by zhebrica, Thu 03/06/2010 17:38:24

Previous topic - Next topic

zhebrica

I'm trying to have a character perform an animation loop constantly, including while the player talks to her, while dialog options are displayed, and while the character is talking. (The idea is that she's busy and doesn't stop what she's doing.)

First I tried setting the animation to play when the room loads and setting the character's talking view to the same loop, which worked except that the animation would stop when dialog options were displayed. So I tried using the RepExec room function, but when I used the same code from my first attempt, the character no longer animated when she was sitting idle. I guess you have to write it differently in RepExec, but I'm not sure how.

This is what I have:

Code: ags
function room_RepExec()
{
  cTree.LockView(16);
  cTree.Animate(1, 7, eRepeat, eNoBlock, eForwards);
}


I tried calling eBlock instead, which did make the animation play, but of course that blocks the player from doing anything.

eta: Whoops, forgot to mention, eventually this character will have to stop animating and do something else, if that matters at all.

barefoot

#1
Hi

why not try: repeatedly_execute_always

Called every game cycle, even when a blocking routine (eg. speech/cutscene) is in progress. You cannot call any blocking functions from this event handler. You can have a repeatedly_execute_always function in both your global script and in any room scripts where you require it.

Its in the Manual...

barefoot
I May Not Be Perfect but I Have A Big Heart ..

zhebrica

Same result with both room_RepExec and repeatedly_execute_always. The animation doesn't play when the character is idle, as it does when I put the same code in room_Load.

Khris

Putting commands like that in RepExec makes them get called every game loop. Thus the animation doesn't get a chance to start as it is immediately restarted the next loop.
What you need to do is manually advance the Character's .Frame property.

Atelier

There's an option in general settings: Run game loops while dialog options are displayed? (True/False)

Does it work when you set it to true?

zhebrica

Quote from: AtelierGames on Thu 03/06/2010 19:21:39There's an option in general settings: Run game loops while dialog options are displayed? (True/False)

Does it work when you set it to true?

When I run the animation from room_Load, yes, this partially works. The animation continues while the dialog options are displayed, but then stops after the character speaks. I guess it's because it called the character's speech view (even though the speech view happens to be the same loop that was already playing). Thanks for letting me know about that option, though. I'm sure it will come in handy for other things.

Quote from: Khris on Thu 03/06/2010 19:05:20Putting commands like that in RepExec makes them get called every game loop. Thus the animation doesn't get a chance to start as it is immediately restarted the next loop.
What you need to do is manually advance the Character's .Frame property.

Okay, that makes sense. One question, though -- how do I specify how fast the frame advances? (I'm using cTree.Frame++; to advance it. Is that what I should be doing?)

Khris

Yes. To avoid getting an error, use GetFrameCountForLoop() to set the frame back to 0.
To achieve the delay, use a variable; increment it every game loop, then check e.g. if (cTree.Frame == 3 && delay_var = 5) before advancing the frame (and resetting delay_var back to 0). This will put a delay of 5 game loops between frames 3 and 4.

zhebrica

Quote from: Khris on Fri 04/06/2010 00:03:51To avoid getting an error, use GetFrameCountForLoop() to set the frame back to 0.

Could you please elaborate on this? I looked up GetFrameCountForLoop and I see what it does, but I'm not sure what I need to do with that number in this case.

Khris

Say the loop has 5 frames, 0 to 4. If you increased .Frame to 5, you'd get an error.

Code: ags
  // advance frame
  if (cTree.Frame == GetFrameCountForLoop(cTree.View, cTree.Loop) - 1) cTree.Frame = 0;  // reached loop's last frame, revert to 0
  else cTree.Frame++;

zhebrica

Okay, I'm still having trouble with advancing the frame. It advances at the correct rate while dialog choices are displayed, while the player character is speaking, and after a dialog ends. But it advances much faster when the room first loads and while the NPC is speaking. (Like I said before, the NPC's speech view is set to the same view I'm working with. I don't know if that has anything to do with it.)

In repeatedly_execute_always:
Code: ags
  Delay++;
  if (Delay == 5)
  {
    if (cTree.Frame == Game.GetFrameCountForLoop(cTree.View, cTree.Loop) - 1) cTree.Frame = 0;
    else cTree.Frame++;
    Delay = 0;
  }

SMF spam blocked by CleanTalk