What is the function in Verse for executing a function after a certain amount of time? Is there an API for setting timers?
Here’s the way’s I’m aware of to do it (I didn’t run these, but I did check them for syntax).
My example assumes you want to call MyCall() (but it could be anything).
You can Sleep() prior to the call, or do a spawn (to let the current Verse code continue) with a sleep and a call in the spawn.
Method 1
Example with a Sleep inline.
# Some code...
Sleep(2.5)
MyCall()
# Any code here will run AFTER the 2.5 second sleep and the MyCall() completes
Method 2
Example using a spawn - this is a bit more complicated, as far as I know spawn only takes a single argument (a single command) - that’s why I make the function.
# Create a function to give spawn which will make the delayed call.
DelayedCall()<suspends> : void =
Sleep(2.5)
MyCall()
# Main code...(would be part of some function)
spawn {DelayedCall()}
# Any code here runs right away
Hope it helps…
3 Likes
You just inspired me to make this function so you don’t need to set Sleep()
methods everywhere. Hope it fits!
EDIT: I just added support for functions that <suspends>
2 Likes
well, that’s super handy! Thanks for sharing
1 Like