DCS func scheduleFunction

From DCS World Wiki - Hoggitworld.com

Scripting Root

Envrioment: Mission Scripting
Function: scheduleFunction Added with: 1.2.0
Member Of: timer
Syntax: functionId timer.scheduleFunction(function functionToCall , functionArgs anyFunctionArguement , time modelTime )
Description: Schedules a function to run at a time in the future. This is a very powerful function.

The function that is called is expected to return nil or a number which will indicate the next time the function will be rescheduled. Use the second argument in that function to retrieve the current time and add the desired amount of delay (expressed in seconds)

Return Value: functionId
Return Example: 3
Examples: The following will run a function named "main" 120 seconds from one the code would run.
 timer.scheduleFunction(main, {}, timer.getTime() + 120)

The following example sets up a repetitive call loop where function CheckStatus is called every 5 seconds or.

function CheckStatus(ourArgument, time)
 -- Do things to check, use ourArgument (which is the scheduleFunction's second argument)
 if ourArgument == 53 and someExternalCondition then
   -- Keep going
   return time + 5
   -- That's it we're done looping
   return nil
timer.scheduleFunction(CheckStatus, 53, timer.getTime() + 5)
Related Functions: timer Functions: getTime, getAbsTime,getTime0, scheduleFunction, removeFunction, setFunctionTime