# Looping too Soon -- probably common sense
Running a ConditionalSleep until the Player is idle.
(ie. not moving AND not animating)
Logical flow should be:
loop(){
takeAction()
waitForIdle()
}
I noticed that the player seemed to be repeatedly clicking to takeAction() rather than actually waiting until the Action stopped, and thus they were idle, before again taking action.
It seemed to happen more frequently when the player had only just arrived at the destination area where the action was to take place.
Threw in some appropriate log() lines to help measure time between actions and began tweaking my conditionalSleeps.
Discover that conditional sleep tests execute *immediately* and then sleep until true, rather than sleeping once before checking; the script was simply executing faster than the player could begin to takeAction.
So I modified the loop.
loop(){
takeAction()
sleep(someTime)
waitForIdle()
}
By adding a short sleep before testing for idle I greatly reduced the amount of excessive clicking which was occurring, however it leaves something to be desired and I am going to be building around it for a bit.
I can theorize a few ways to manually go about getting a script in sync with the game's tick-cycle, however I feel like there's likely something simple in the API which I am overlooking.
sleep(600); // ie. sleep for a gameTick, thus you are within the next gameTick (or however many tick you need) when you have started your action
Sleeping until the next game tick should be sufficient in most cases, especially low-risk ones; but knowledge is power so I will update as I learn more. As a stickler I'd prefer for my conditionalSleep to start being tested ASAP (after the player has actually begun their action), The next tick starts 1 to 600 ms from <now> and I'd prefer to know as precisely as possible, my theories for manual measurement would suffer in high-latency situations; guess it's time to read a lot of documentation.