Character pacing as background process

Started by paolo, Thu 20/09/2007 19:21:53

Previous topic - Next topic

paolo

I don't know if this one's been answered before (searching for "pace" or "pacing" gives too many false positives containing "space" or "spacing") but it might well have been, as I'm sure others have wanted to do the same thing.

I have a cutscene which I want to end with a non-player character continuously pacing up and down, occasionally saying things, and continues to do so even while the user has control (until they do the right thing that will stop the character from doing this).

There are two aspects to this:

* How can I get the character to walk up and down even after control has returned to the user? I could write something like:

while (true)
{
  cMyChar.Walk(x1, y1);
  cMayChar.Walk(x2, y2);
}

but this is blocking and would never return control to the user.

I tried

  cMyChar.Walk(x1, y1, eNoBlock);
  cMayChar.Walk(x2, y2, eNoBlock);

but the character didn't move at all - maybe control was returned immediately, or possibly my character wasn't on a walkable area, but I'm fairly sure she is.

(EDIT: Of course, the above are equivalent: eNoBlock is the default value.)

I think I need to use something like repeatedly_execute() or repeatedly_execute_always(), but the pacing is not something I need to be done every game cycle.

* The second problem is having my character say things (phrases taken at random from a list, and at random times) as she is pacing. I can code up the random selection of phrases easily enough, but again am wondering how I can get this to happen while the user has control of the game. This exact thing has been done before by Cinfa in his game Roccio's Quest, so maybe I should PM him to find out how he did it. His character did not pace but followed another, but the talking aspect would be the same.

Thanks for any help.

Ashen

#1
The first probelm is, since you have two non-blocking Walk commands, AGS will try to execute them both at once, and the character won't move anywhere.

The second problem is, you didn't read the manual. I can't say for sure if this is how Cinfa did it, but AddWaypoint  allows you to 'queue' movements. For an example of using it to have a character pace, check my post in this thread. The rest of the thread has some other ways of dealing with it, too.

EDIT:
Reopened. Sorry, missed the talking part. That's been covered too, I think, but it's not as obvious (as in, no specific command to do it). Try using SayBackground and a Timer to have them say things at random times. It should be easy enough to randomise what's said, as well, if you wanted.
I know what you're thinking ... Don't think that.

paolo

#2
Thanks. I've used a variation on the code from the other thread, and added some code to do the random talking more or less in the way you suggested, Ashen (although I didn't read your edited reply until after I had done it). In case others would like to be able to do the same thing, here's an outline:

* Set up some global messages - these must be numbered consecutively
* In your code, set a variable (character_saying_messages) to true to indicate that the character should now start saying the messages (and set it to false when you want the character to stop talking)
* Then in repeatedly_execute() in the global script (this is just pseudocode):

if (character_saying_messages)
{
   if time since character last said something > time limit plus some small random number of cycles (to make the messages come up after intervals of varying lengths; for the time limit, use 40 times the number of seconds you want to wait)
   {
      message number = x + random(y) (where x is the number of the first global message you want to use and y is the result of subtracting x from the number of the last global message)

      c(your character's name goes here).SayBackground(Game.GlobalMessages[message number]);
      reset time since character last said something to zero
   }
   else
   {
      add one to time since character last said something
   }
}

Radiant

Quote from: paolo on Fri 21/09/2007 08:55:04
   if time since character last said something > time limit plus some small random number of cycles

SetTimer and IsTimerExpired are your friend.

SMF spam blocked by CleanTalk