First time sharing code on the forums, so forgive me for any mistakes I may make.
This function waits for the variable you pass in to become truthy,
or for the function you pass in to return a truthy value.
You can customize the interval at which it will run the check, as well as the maximum amount of time to wait for.
The code is hosted on GitHub.
Any kind of feedback and contribution is very appreciated!
Here are some examples:
Code: Select all
; Example #1
; This will wait 1 second before setting x to true.
setTimer () => x := true, -1000
; This will consequently wait at least 1 second before continuing.
wait x
Code: Select all
; Example #2
; This will wait until the Spacebar is pressed,
; but will check for it much more frequently than KeyWait would.
wait () => getKeyState("Space"),, 10
Code: Select all
; Example #3
; This is exactly equivalent to the previous example.
wait func("getKeyState").bind("Space"),, 10
Code: Select all
; Example #4
; This will wait for Joystick #1 to be plugged in
; and display its name on the screen.
msgbox "Joystick '" wait(() => getKeyState("1JoyName")) "' has been plugged in!"