The onLoop is just a while loop which continues until the user presses the red 'stop' button, where the return value is a millisecond delay between loops. You can use it as you wish. The 'design pattern' I described, where only a single game interaction happens per loop, is safest as this makes the script deterministic. And yes - a 'walk path' call could also fail (potentially even mid-route). For example, your network connection could drop for 5 seconds. Your script needs to be able to be able to handle the possibility of this.
-Apa
Edit: About conditional sleeps for this particular situaton: I would sleep until the 'open trapdoor' object exists, rather than waiting for animation.