wait – Wait for any variable to become true or any function to evaluate to true

Post your working scripts, libraries and tools.
User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
Location: Germany
Contact:

wait – Wait for any variable to become true or any function to evaluate to true

Post by SALZKARTOFFEEEL » 12 Nov 2019, 14:19

Hi everyone!
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!"

SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: wait – Wait for any variable to become true or any function to evaluate to true

Post by SOTE » 12 Nov 2019, 16:00

I think this is a wonderful and it's great that you shared.

Please don't take this the wrong way, but I think putting just a function under GPL is unnecessary and even odd. It's arguably much better to put such under the MIT license (where it has your name as the copyright holder) or public domain (CC0). Wait functions are not new and exist in many other programming languages, so it's not like something radically new was created that nobody has ever done anything similar, or that it needs to be protected from others using it commercially.

User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
Location: Germany
Contact:

Re: wait – Wait for any variable to become true or any function to evaluate to true

Post by SALZKARTOFFEEEL » 12 Nov 2019, 16:54

SOTE wrote:
12 Nov 2019, 16:00
I think this is a wonderful and it's great that you shared.
Thank you!
SOTE wrote:
12 Nov 2019, 16:00
Please don't take this the wrong way, but I think putting just a function under GPL is unnecessary and even odd. It's arguably much better to put such under the MIT license (where it has your name as the copyright holder) or public domain (CC0). Wait functions are not new and exist in many other programming languages, so it's not like something radically new was created that nobody has ever done anything similar, or that it needs to be protected from others using it commercially.
Good to know. What license to use was a quick second decision – I just used GPL because I knew (or thought) it was very permissive.
I should do some reading as to what license is more appropriate, starting with the MIT license you talked about.
Will probably switch over to something else tomorrow then. Thank you!

guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: wait – Wait for any variable to become true or any function to evaluate to true

Post by guest3456 » 28 Nov 2019, 00:39

SALZKARTOFFEEEL wrote:
12 Nov 2019, 16:54
Good to know. What license to use was a quick second decision – I just used GPL because I knew (or thought) it was very permissive.
I should do some reading as to what license is more appropriate, starting with the MIT license you talked about.
Will probably switch over to something else tomorrow then. Thank you!
GPL is one of the most restrictive licenses. it is like a virus, requiring all new code based on it to also use the GPL.

MIT is very permissive, so is WTFPL


Post Reply

Return to “Scripts and Functions (v2)”