DCS World Typescript
    Preparing search index...
    interface l_timer {
        getAbsTime(): number;
        getPause(): boolean;
        getTime(): number;
        getTime0(): number;
        removeFunction(functionId: number): void;
        scheduleFunction<T>(
            functionToCall: ScheduledFunction<T>,
            functionArgument: T,
            modelTime: number,
        ): number;
        setFunctionTime(functionId: number, modelTime: number): number;
    }

    Hierarchy (View Summary)

    Index
    • Returns the game world time in seconds relative to time the mission started. Will always count up from when the mission started. If the value is above 86400 then it is the next day after the mission started. This function is useful in attaining the time of day.

      Assuming a mission started at noon the value returned would be 43200. (126060). Midnight would be 0. Calling this function at 12:00:10 timer.getAbsTime will return 43210.xxx.

      Returns number

      Absolute mission time-of-day in seconds.

      `const secondsSinceMidnight = timer.getAbsTime();`
      
    • Reports whether mission model time is paused.

      Returns boolean

      Pause state.

      `if (timer.getPause()) env.info("Mission paused");`
      

      %DCS_INSTALL_DIR%/Scripts/UI/ConsoleCommands.lua:371

    • Returns the model time in seconds to 3 decimal places. This counts time once the simulator loads. So if a mission is paused, the time this function returns still moves forward.

      Returns number

      Elapsed mission model time in seconds.

      `const runAt = timer.getTime() + 10;`
      
    • 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).

      Type Parameters

      • T

      Parameters

      • functionToCall: ScheduledFunction<T>

        Callback receiving the supplied argument and scheduled model time.

      • functionArgument: T

        Value passed unchanged to the callback.

      • modelTime: number

        First execution time in mission model seconds.

      Returns number

      Numeric schedule identifier used to reschedule or cancel the callback.

      const functionId = timer.scheduleFunction(
      (message: string, time) => {
      env.info(message);
      return time + 60;
      },
      "Runs every minute",
      timer.getTime() + 60,
      );
    • Re-Schedules an already scheduled function to run at a different time in the future.

      Parameters

      • functionId: number

        Identifier returned by scheduleFunction.

      • modelTime: number

        New execution time in mission model seconds.

      Returns number

      The model time at which the callback is now scheduled to run.

      const newRunTime = timer.getTime() + 30;
      const scheduledTime = timer.setFunctionTime(functionId, newRunTime);
      env.info(`Rescheduled for ${scheduledTime}`);