Moving NPC on every turn ADV3Lite

Hello,

I want to have my NPC “patrol” around a grid of rooms on every turn until the PC is either captured or finds the target destination.
I am trying to use a Daemon to accomplish this but the NPC doesn’t seem to budge.
I put the following code in the PC start room (of this puzzle). And honestly this is copied straight from the LearningT3Lite.pdf


sky2G : Room 'sky' 'sky'
  "You see clear skies ahead. 2G"
  south = sky2A
  southeast = sky2A 
  southwest = sky1A 

  startFlight()
  {
    flightDaemon = new Daemon(self, &flight, 1);
  }
stopflight()

{
  if(flightDaemon != nil)
  {
    flightDaemon.removeEvent();
    flightDaemon = nil;
  }
}
flightDaemon = nil
flight() { flightEvents.doScript(); }
flightEvents: CyclicEventList
{
  [
      nidhogg.moveInto(sky2G),
      nidhogg.moveInto(sky1F),
      nidhogg.moveInto(sky2E),
      nidhogg.moveInto(sky3F)
  ]
}
;

Any help is appreciated.
Deborah

3 Likes

Just eyeballing this, but I believe the problem is here:

The event list of moveInto() needs to be a list of function pointers. As it stands, your list is being populated by the return value of each moveInto() (so a list of nil’s, since that method doesn’t return a value).

Again, off the top of my head, I think you want this:

flightEvents: CyclicEventList
{
  [
      function () { nidhogg.moveInto(sky2G); },
      function () { nidhogg.moveInto(sky1F); },
      // ... etc.
  ]
}

Which can be reduced to the function short form like this:

flightEvents: CyclicEventList
{
  [
      {: nidhogg.moveInto(sky2G) },
      {: nidhogg.moveInto(sky1F) },
      // ... etc.
  ]
}

(Note the colon, that’s required.)

3 Likes

Coming from an adv3 background, but my tendency would have been to put that eventList in the NPC’s takeTurn (or equivalent) method…

2 Likes

adv3Lite has a takeTurn() as well, so that could work too.

4 Likes

takeTurn() along with the function short form in the eventList, works great.

Thank you!

3 Likes

That’s great, but be sure to call inherited() in it along with your own code, since the adv3Lite library uses takeTurn() to do a lot of Actor-related housekeeping.

3 Likes