lost in code of my own making, need debug tips (adv3Lite)

Help! I’m lost in a twisty little maze with exits in all directions! Don’t know where to go next!

I admit, it’s a problem of my own making. I am nearing the final scenes of the game, so it’s a bit complex to isolate in a test-bed environment and a bit long to be posting code, but here’s the problem as best as I can describe it…

Harry rescues Grace, who is bound and gagged in an upstairs room. The act of releasing her bonds triggers a grace.fDaemon, and Grace starts following Harry down the stairs, through the house, into the basement and into a hidden room. They meet up with Aaron, and Harry starts following Aaron, with Grace still following Harry. Max has also joined the party, following Harry as he follows Aaron.

So far, so good.

Thanks to help received yesterday on the FollowAgendaItem, everything was working great. Everybody was following as designed.

Then I did something and the whole house of cards came crashing down. What? Don’t know. That’s the twisty little maze I’m stuck in.

The code where grace followed Harry through the house has been in place for some time, and I did not edit it yesterday.

The crash occurred after I tried to bring in two more characters into the hidden room in the basement.

There is a commotion somewhere in the house, triggered by a Daemon that runs a StopEventList, and when it’s done, Lolita and Felipe join the crowd in the basement.

But suddenly, I discover that Grace no longer follows Harry out of the upstairs room, way back in the house, several moves prior. I haven’t touched any of that code for quite some time, but Grace no longer follows Harry down into the basement.

I see in the debugger that grace.fDaemon is not nil—she should be following.

But she doesn’t.

The initial sequence is, in the upstairs room when her bonds are cut, the fDaemon is triggered—which does happen, I can see it in the debugger—but when Harry leaves the room, she stays put.

This all worked yesterday afternoon (before I tried to bring Lolita and Felipe into the picture), now it doesn’t. I can see nothing in the lolita or felipe actor code that should have anything to do with grace suddenly not following several moves back, when she has been following reliably for some time prior to my mistake (whatever that may have been; I’m guessing I fat-fingered some existing code, but it does still compile correctly).

I know this is a long shot, but any tips on what I should look for would be appreciated.

Are there any values that I can examine in the fDaemon in the debugger that might shed some light on the problem? (I’ve looked, but nothing jumps out. It’s a complex structure, though, so maybe there’s something I should look for?)


Well, I have no idea what’s causing this, of course, although I know the feeling when one apparently unrelated thing causes something else to stop working; I experienced it earlier today in my own development work (though I did eventually manage to track down the cause).

But to get back to your problem, probably the first place I’d try setting a break-point is right at the start of the followDaemon() method on the Actor class. That’s the method that should run every turn on every actor for which fDaemon isn’t nil. What I’d want to see is whether it runs on the grace object every turn from when you think Grace’s fDaemon should be triggered, especially after you move Harry. The logic of the followDaemon() method is that it checks to see if the Actor it’s running on is in a different room from the player character; if it is it tries to move the Actor through the same TravelConnector that the player character just left by; if it doesn’t have a note of that travel connector then it just moved the Actor into the player character’s new room.

If the followDaemon method is executing but not working properly, then the most likely thing that could be wrong is the pcConnector property, which should hold the value of the connector the Actor last saw Harry travel through; if it doesn’t you need to go back to where this property is being set, which is in the beforeTravel() method of the Actor. I can see one thing that might possibly go wrong here, since when I wrote this code I didn’t stop to consider the case where the PC is following one actor and being followed by others. So, what may be happening here is that a followAgendaItem on the Actor is blocking the setting of the pcConnector property and leaving it at a spurious value, which could indeed cause problems.

This shouldn’t happen in the normal course of events, since you’d have to have set a followAgendaItem on the same actor that you wanted to follow Harry (and if you try to get Harry and Grace to follow each other at the same time you’re bound to get problems!), but if you’ve somehow got code that’s setting a followAgendaItem on Grace instead of Aaron, that might be the cause of the problem. In any case, Actor.beforeTravel() is another method you could try setting a breakpoint in to see what’s happening to the value of pcConnector if it looks like followDaemon() is picking up a strange value for this property.

If, on the other hand, grace.followDaemon() isn’t executing at all (which I suspect is more likely to the problem) you need to track down why. The place I’d probably start for that is in the method eventManager.executeTurn() (in events.t). I’d want to see what eventManager.eventList contained at the start of this method (it should contain the grace.fDaemon, though it might be hard to identify it - you need to expand the list and look for a Daemon whose obj_ property is grace). If Grace’s Daemon is there, step through the code until lst is evaluated. Then see if Grace’s Daemon is in lst. If not then the likely problem is that Grace’s fDaemon’s nextRunTime has fallen too far behind the current turn count, given by libGlobal.totalTurns. This could happen, for example, if the call to grace.startFollowing() takes place too late on the turn, which could only happen if you called graceStart.following() from within another Daemon (or Fuse).

This leads me to the thought that the culprit might somehow be this:

So something else I’d try is commenting out that Daemon to see if that cures the problem. If it does, then you need to try to figure out the interaction between your commotion Daemon and the Daemon that should be running Grace’s following efforts.

I’m not sure if any of that will actually help, but it’s about the best I can come up with.

Yes!!! Thank you!!! :slight_smile:

grace.followDaemon() was not executing.

I was setting her off on her journey from within a Scene. Thanks to your debugging tip (set a break point in eventManger.executeTurn() and step through to examine lst) plus your suggestion to look at conflicts with a Daemon or Fuse (wasn’t those, but it was a Scene) I was able to determine the problem.

I’ve now moved the startFollowing() call to grace.beforeTravel() and it works.

Yes, I know, you advised me previously to start following in beforeTravel() and I thought I had done so. Turns out, I had. But when I placed it in the beforeTravel() I did not remove it from the Scene, so the code had two of them. I guess—don’t specifically remember it, but it seems to be a logiical answer—one of the things I did yesterday was remove the redundancy. I just removed the wrong one.

Now I am back in business, and all the wiser for the experience, I guess. :slight_smile:

Again, thanks.


I’m glad you were able to find the problem and sort it out! :slight_smile:

This is not an obviously inappropriate thing to do, and it looks like a problem other people could easily encounter. Now you mention it, I can see it’s effectively the same issue as (or very similar to) the one we encountered with using startFollowing from an AgendaItem. For the next release I’ll apply the same fix as I did for AgendaItems (namely to make sure the Scene mechanism runs before Fuses and Daemons instead of among them), so hopefully this particular problem won’t afflict anyone else after the next release. A quick test suggests that this fix seems to work okay.