Why do my scripts lock up on the "Wait for NPC" command?
Some people complain that their scripts lock up when using the wait for NPC command. This happens because of misunderstandings about the way the command works.
One common mistake is to do something like this:
walk NPC(5) wait for NPC
You might assume that this will wait for the last NPC moved. This is not so. If you do not specify a specific NPC to wait for, then it will wait for NPC 0... but who knows what NPC 0 might be doing at the moment. So, the correct commands would be:
walk NPC(5) wait for NPC(5)
If these two lines are a common occurance in your code, you may want to streamline the process by creating your own script:
script, walk npc and wait, npc, dir, distance=1, begin walk npc (npc, dir, distance) wait for npc (npc) end
Perhaps that was not your problem? Another possibility is that you have not stopped automatic NPC movement with the suspend NPCs command. The "wait for NPC" command cannot tell the difference between scripted movement and automatic movement, so if you leave automatic movement on, the NPC might *never* stop moving.
One last possibility is that you have given the NPC a speed which does not divide evenly into 20. All map tiles are 20x20 pixels. If you give an NPC (or a hero) a speed that does not divide evenly into 20, it may become misaligned with the tiles, and will get stuck mid-step. If this happens, your "wait for NPC" command could appear to lock up.