Thanks, Kieran.
I've identified two issues here:
1. On room entrance (in CCurrentGame::SetMembersAfterRoomLoad), first global scripts are processed, and then monsters in the room are pre-processed. This is fine, but any NPCs processed here that execute "
Imperative Make Script Global"
were not actually getting moved over to the global scripts list at this point. It doesn't happen until after the first move is made in the room, which is incorrect. Fixing this oversight corrects the issue you've noted.
2. However! If you add a "
Wait 0"
to the top of your default script, the issue resurfaces (same as before). This gets to the root cause of the issue you noted: each turn, first the monsters are processed, and then global scripts are processed. Note this is in the opposite order from the order of global-then-room on room entrance noted in (1) above. So, when an NPC is made global, it gets to run in the monster list, and then it runs again on the same turn in the global scripts list. This second iteration of processing shouldn't happen on the same turn.
Please let me know if I've lost you with my explanation yet.
My thoughts at this point:
First, it's somewhat unfortunate that entities are processed in an inconsistent order across (1) and (2). I can see reasons for doing both, and we probably don't want to change any ordering at this point.
To fix the issue you reported, I'm adding code to ensure NPCs that run "
in room"
don't process their scripts again as a global script on the same turn. Can't think of a more elegant solution for this while leaving global/in-room processing ordering as-is.
Feel free to share your thoughts.
____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.
[Last edited by mrimer at 10-26-2020 11:05 PM]