Jump to content

Sleep Function for Lua


Go to solution Solved by Grimes,

Recommended Posts

Posted

I am a software dev (C, Python, Java, the list is actually kind of long), but I’m brand-spanking-new to Lua.  Fortunately it seems pretty straight-forward (it reminds me of Ruby a little). 

Anyway, apparently Lua does not have a built-in sleep() or wait() function, and the workarounds I’ve found so far all require libs of some sort.  It looks like I can also write a C wrapper for it, but I don’t fully understand how DCS implements the language.  I imagine a Lua interpreter is packaged in DCS, but I don’t know how it would use something like LuaRocks packages, and I don’t know if wrapping C will work in DCS.

Hence a couple of  questions:

#1. Does the DCS interpreter include any common libs. Like ‘os’’?

#2 How do you deal with time delays.  For instance, start 3 uncontrolled groups, at 120 second intervals.

I include Mist and Moose in all of my missions, but I haven’t delved into all the docs yet.  I needed to include Mist to get witchcraft running, and I’ve only used Moose for RAT so far.

Any advice is appreciated.

Thanks.

 

 

 

 

 

 

  • Like 1

Rex's Rig

Intel i9-14900K | Nvidia RTX 4090 | 64GB DDR5 | 3x4TB 990 Pro M2 SSDs | HP Reverb 2 | 49" Samsung 5120x1440 @ 120Mhz

TM Warthog Stick + Throttle | TM Pendulum Pedals | MS Sidewinder 2 FFB | Track IR |  Cougar MFD x 2 

 

  • Solution
Posted

DCS automatically erases a few libraries like io, lfs, and os, but you can re-enable that by manually editing Scripts/MissionScripting.lua. This is required for plenty of missions that have any sort of persistence built in. 

 

Time delays are done by putting what is needed into a function and scheduling it to run at a later time. 

local function myFunction()
  spawnGroup("gp1")
end
timer.scheduleFunction(myFunction, {}, timer.getTime() + 120)

 

  • Like 1
  • Thanks 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted

awesome, thank you!

  • Like 1

Rex's Rig

Intel i9-14900K | Nvidia RTX 4090 | 64GB DDR5 | 3x4TB 990 Pro M2 SSDs | HP Reverb 2 | 49" Samsung 5120x1440 @ 120Mhz

TM Warthog Stick + Throttle | TM Pendulum Pedals | MS Sidewinder 2 FFB | Track IR |  Cougar MFD x 2 

 

Posted (edited)

If you sleep the Lua mission thread then you'll pause the simulation, but for future thought when I do need to make Lua sleep I have a function that solves some complex math in a for loop and i've roughly got it to take a float to determine how long the loop should run (keep solving) and thus pause the thread, in seconds.

Edited by PravusJSB

Creator & Developer of XSAF ::An AI model that wants to kill you, and needs no help from humans.

Discord: PravusJSB#9484   twitch.tv/pravusjsb  https://www.patreon.com/XSAF  https://discord.gg/pC9EBe8vWU https://bmc.link/johnsbeaslu

Work with me on Fiverr: https://www.fiverr.com/pravusjsb

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...