Pausing / delay from Lua script

  • #1, z Raven SingularityWednesday, 19. April 2017, 05:17 hodinky 8 years ago
    I was trying to figure out the equivalent to "Miscellaneous > Pause > 500ms" to insert a delay for my object animations, but I can't find any information online.  The only mention of pausing a script I could find was this:


    But there was no mention of an equivalent to "Miscellaneous > Pause" in Lua.

    Is it not possible to set a simple delay in milliseconds from a Lua script?

    I am trying to call a object:to(), then wait 250ms, then start the next transition.  It is aggravating needing to break up my Lua animation routine with "Pause for 250 milliseconds", then another Lua script for the next transition, repeat, repeat, repeat, argh!

    Bažant

    18 Posts


  • #2, z sebastianWednesday, 19. April 2017, 08:19 hodinky 8 years ago
    there is no builtin pause or sleep function out of the box with lua. 
    I found some examples here:

    (some of them require external libraries) 

    also i would not recommend to use it (much) in lua because i don't know how it interferes with Visionaires environment. 
    Maybe the devs have a bit more farsightedness =) 

    Kapitán

    2346 Posts

  • #3, z ke4Wednesday, 19. April 2017, 08:39 hodinky 8 years ago
    I suppose you could set up a loop like this:

    1. Execute script ( object transition part 1 )
    2. Pause for 250 ms
    3. Execute script ( object transition part 2 )
    4. Pause for 250 ms
    5. Jump to action part #1

    Zabiják klíčů

    810 Posts

  • #4, z afrlmeWednesday, 19. April 2017, 11:33 hodinky 8 years ago
    I suppose you could set up a loop like this:

    1. Execute script ( object transition part 1 )
    2. Pause for 250 ms
    3. Execute script ( object transition part 2 )
    4. Pause for 250 ms
    5. Jump to action part #1
    Well, yeah, you do it inside of a called by other action block. That usually how I handle such matters. It's possible to use the getTime() function thing directly in a Lua script function too, but it's not a very nice way to go about it.

    @ Raven: I recommend doing what ke4 says to do inside of a called by other action block. You need to remember to manually quit the looping action block inside of an at end of scene action otherwise it will keep on swimming, keep on swimming, just keep on swimming as Dory says!

    https://i.gyazo.com/8a09d5051a13fc2e631fcd5afff3832b.png

    P.S: Lua has no built in pause/delay solution. The thread you linked earlier that links to a script I shared on the wiki, but seemingly wrote no tutorial on how to use it, is based on tables. You create something & it creates a table containing various information, then uses 2 loops I think. 1 to check time passed & see if it's the same or greater than time passed in the table & if so then it loops a function or something... I forget. It's ages ago since I wrote it & it's not something I have used since.

    The bigger problem is inserting a pause directly into a function. It won't work unless it's a looping function, which means it has to belong to a mainLoop & then you need to add various if queries to it to prevent various Lua lines from being executed while you wait until x time has passed. It's just not a pretty way to go about things. I really wish Lua had a built in delay system, but it doesn't & it's not like the VS devs can sort it out as Lua script is written / created by a third party & is used in lots of applications & game engines - including CryEngine.

    Imperátor

    7285 Posts

  • #5, z MachtnixWednesday, 19. April 2017, 11:48 hodinky 8 years ago
    My solution from old DOS-days: let Lua something difficult to do, perhaps a loop to make a square root from 1 to 2 billions.  wink

    Kapitán

    1097 Posts

  • #6, z SimonSMonday, 24. April 2017, 13:18 hodinky 8 years ago
    Just to mention it before the documentation is ready, there's a new function in RC0 to schedule a function call:
    function callback()
      print("called")
    end
    
    setDelay(1000, "callback()")
    setDelay(1000, function() print("called") end)
    setDelay(1000, callback)

    You can use the function as variable, use a string or an anonymous function.

    Kapitán

    1582 Posts

  • #7, z afrlmeMonday, 24. April 2017, 14:18 hodinky 8 years ago
    @ Simon: nice one mate. Sure it will come in handy. wink

    Imperátor

    7285 Posts