Fantasy Grounds Fridays Pre

Thread: Delay in Lua?

  1. #1

    Delay in Lua?

    Does anyone know if there is a way to implement a visible delay using Lua?

    I've tried with os.clock like this but it doesn't delay in execution order, it seems to delay the whole function it's in from executing (even if this is at the end of the function):

    			local start = os.clock();
    			while os.clock() - start < 1.0 do end
    I suspect it has something to do with how FG threads.


  2. #2
    There is no function to delay the scripts. Because the UI fires events and interacts with the Lua engine all the time and change the state of objects, it is single threaded (or else lots of assumptions and code would break). So, you can't introduce delays into any Lua code without delaying the whole engine.

    The alternate answer is probably some sort of timer support in the Lua coding; but that's not currently on our radar.


  3. #3
    Yeah, os.clock() works but does delay the whole engine. Too bad.

  4. #4
    Quote Originally Posted by zuilin View Post
    Yeah, os.clock() works but does delay the whole engine. Too bad.
    It would be really nice to have a non-blocking timer event system.
    Fantasy Grounds AD&D Content Bundle (All The AD&D Content)
    Coding the Official AD&D Ruleset
    Documentation for AD&D 2E ruleset.
    My Twitch Channel for AD&D and FG related streams (See schedule for live days)
    My YouTube for FG related Tutorials and AD&D Actual Plays
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)

  5. #5
    Think of it as a single thread going through things you want done - and if you want to keep doing "other things" and come back to this thing your trying to delay - you'd have to constantly have things checking that stored time to see "are we there yet?" periodically throughout your code - and then be able to do whatever it was you delayed whenever that happened. Not pretty. But I know no other way. If you find one make sure you update this thread.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
SWADE Playlist

Log in

Log in