Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Timer to the Lua API to suspend interactive scripts #3251

Closed
API-Beast opened this issue Apr 14, 2022 · 1 comment
Closed

Add a Timer to the Lua API to suspend interactive scripts #3251

API-Beast opened this issue Apr 14, 2022 · 1 comment
Assignees
Labels
feature Feature request, or something should be improved scripting Related to scripting API time-3
Milestone

Comments

@API-Beast
Copy link

API-Beast commented Apr 14, 2022

Right now the only way to wait for some time in a lua script is to do a busy wait:

function sleep(a) 
    local sec = tonumber(os.clock() + a); 
    while(os.clock() < sec) do 
    end 
end

However this will lock up the entire program until the sleep function has returned.

If a Timer class or similar would be added, or simply a callback that is called every n seconds it would open up some new ways scripts can interact with the user. In my case I was trying to implement a timeout to WebSocket so that if it hasn't managed to connect yet after 3 seconds it would stop trying to connect and update the UI to allow the user to manually restart the connection process.

API could look something like this:

local timer = Timer{delay=1.0, onTick=function() print("Tick Tock") end, repeat=true}
timer:start()
@dacap dacap added feature Feature request, or something should be improved scripting Related to scripting API time-3 labels Apr 18, 2022
@dacap dacap self-assigned this Feb 22, 2023
@dacap dacap added this to the v1.3.0 milestone Feb 22, 2023
@dacap dacap closed this as completed in c2f8335 Feb 22, 2023
@BananaChad

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request, or something should be improved scripting Related to scripting API time-3
Projects
None yet
Development

No branches or pull requests

3 participants