How to set a timer

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
Eboreg
Posts: 309
Joined: Wed Mar 13, 2019 10:35 pm

How to set a timer

Post by Eboreg »

So... I've been looking in to setting a timer for an event to go off, say... five minutes after a previous event was fired. i.e. a side has been told to change from weapons hold to weapons tight and I want to reset it back to weapons hold 5 minutes later. However, the lua code I have now sets the timer to go off at Jan 1, 1 AD at 0000Z. What am I doing wrong?

Code: Select all

local current = ScenEdit_CurrentTime()
local newtime = current + (5*60)
local trigger = ScenEdit_SetTrigger({description='Check For Stand Down', Time=newtime})
User avatar
blu3s
Posts: 1117
Joined: Fri Jul 08, 2022 9:45 am

Re: How to set a timer

Post by blu3s »

Code: Select all

local newTime = os.date('%d/%m/%Y %H:%M:%S', ScenEdit_CurrentTime() + (5*60))
local trigger = ScenEdit_SetTrigger({description='Check For Stand Down', Time=newTime })
Eboreg
Posts: 309
Joined: Wed Mar 13, 2019 10:35 pm

Re: How to set a timer

Post by Eboreg »

blu3s wrote: Mon Oct 21, 2024 6:53 am

Code: Select all

local newTime = os.date('%d/%m/%Y %H:%M:%S', ScenEdit_CurrentTime() + (5*60))
local trigger = ScenEdit_SetTrigger({description='Check For Stand Down', Time=newTime })
Tried to run that code and this is what I got

Code: Select all

ScenEdit_SetTrigger 0 : ,Error in Trigger.Time!
User avatar
blu3s
Posts: 1117
Joined: Fri Jul 08, 2022 9:45 am

Re: How to set a timer

Post by blu3s »

Mmm, maybe you need to set the format time to your locale format time
Eboreg
Posts: 309
Joined: Wed Mar 13, 2019 10:35 pm

Re: How to set a timer

Post by Eboreg »

blu3s wrote: Mon Oct 21, 2024 4:33 pm Mmm, maybe you need to set the format time to your locale format time
That... sounds like it would break if I put it on another computer.
User avatar
blu3s
Posts: 1117
Joined: Fri Jul 08, 2022 9:45 am

Re: How to set a timer

Post by blu3s »

You're right


Can you try this on a new scenario?

Code: Select all

local newTime = os.date('%d/%m/%Y %H:%M:%S', ScenEdit_CurrentTime() + (5*60))
local trigger = ScenEdit_SetTrigger({description='Check For Stand Down',mode='add',type = 'Time', Time=newTime })
Eboreg
Posts: 309
Joined: Wed Mar 13, 2019 10:35 pm

Re: How to set a timer

Post by Eboreg »

It set the time to Midnight, January 1st of Year 1
User avatar
KLAB
Posts: 492
Joined: Tue Feb 27, 2007 5:24 pm

Re: How to set a timer

Post by KLAB »

https://www.matrixgames.com/forums/view ... 6&t=275815

Search on this sub forum, timer issues and the LUA text needed has been covered at length.
I'm not on PC otherwise I'd find you the LUA code myself.
Cheers
K
Post Reply

Return to “Lua Legion”