I’m using PunyInform 5.14, and I’ve found that the each_turn routine in a room won’t run unless the room is lit. Is that a bug?
each_turn is run for location + everything in scope.
When the player is in darkness:
locationisthedark, i.e. Darkness- Only the player and the items directly in the player’s possession, are in scope, by default
Thus, thedark.each_turn() is run, rather than each_turn for the room on the map that the player is in.
This is by design, and it works the same way in the Inform 6 standard library.
Thanks!
On closer inspection, it’s actually not even possible to assign an each_turn routine to thedark, without hacking a library file. On the other hand, you can put the functionality in a separate object, which you put in scope whenever the player is in darkness, or you can put it in selfobj (the object representing the player), or in a daemon, etc.
Yeah I just tried it, and the property becomes -1 instead of the real number of the routine. DM4 mentions that routine properties can be replaced, so this is quite unexpected.
Thanks for the alternate solutions, I’m sure I’ll find some solution to what I’m trying to do ![]()
P.S. I tried a daemon, but found that the routine ran on the turn just after the player turns on a light source. I was checking like this: if (location == thedark && real_location == Crypt). I guess that doesn’t work because _UpdateDarkness runs later than the each_turn handlers?
Only if the property is defined in the first place. You can’t add a property to an object that never had it.
This is why Fredrik mentioned hacking the library file.
Indeed. You can see the exact sequence of events in the routine EndTurnSequence, around line 2260 in puny.h.
You should be able to call _UpdateDarkness from your own code, when a light source is switched on or off. If you do this in an after routine, the player will be moved to thedark at that point if needed.