Jump to content

Recommended Posts

Posted (edited)

Hi,

What is the expected format for timer.scheduleFunction with several parameters ?

I can get it working with one parameter for exemple timer.scheduleFunction(myFunction, onePar, timeT) but can't with 2 or more parameters...

I tried with for exemple timer.scheduleFunction(myFunction, {Par1, Par2, Par3}, timeT) as the wiki seems tu suggest to but no luck

Thanks

 

Edit : got it. myFunction with only one table parameter...

Edited by CougarFFW04
Posted

Hi,

Does anybody know if there is a way to get the time at which the function will be executed.

timer.scheduleFunction seems to always return 1 which I think simply means that it was succesful.

Thnaks

Posted
2 hours ago, CougarFFW04 said:

Does anybody know if there is a way to get the time at which the function will be executed.

I'm not sure I understand your question. You tell timer.scheduleFunction() when with the last parameter. That is when it will be executed

Posted

Sorry, I must be daft. Can you post an example?

In my call 

timer.scheduleFunction(theArtilleryZones.update, {}, timer.getTime() + theArtilleryZones.updateDelay)

The method will be invoked now plus whatever the updateDelay is. Are you perhaps given a reference to a timer and want to find out when that timer is scheduled?

Also note that timer.scheduleTime() returns an ID that identifies it when you want to cancel it with removeFunction()

 

Posted

Ah - indeed. You'd have to save the result for the random function first, and then add it to getTime. If it's important to know which timed function is scheduled when, add it to a table indexed by the ID that scheduleFunction returned, and save the result of getTime() and random as value. I don't think DCS provides you with an easy accessor function that returns you the time that a function is scheduled to be invoked, not even if you can provide the ID. 

  • 2 weeks later...
Posted (edited)

Hi,

Another problem with the timer.scheduleFunction.

I have no problem to use it with my how function with one or several parameters and it works as expected.

Now I would like to use it with a native DCS function to change a Flag parameter with the goal to execute something at regular time interval. So in the ME triggers I set a new "switch condition" with as a rule the folowing Lua predicate:

if trigger.misc.getUserFlag('switchFlag') == 0 then return true end

and as the action the following

trigger.action.setUserFlag('switchFlag',1)
timer.scheduleFunction(trigger.action.setUserFlag,{'switchFlag',0},5)

So in principle when switchFlag is equal to 0 the action is triggered and flag is set to 1 until it switches again to 0 (5 sec later in this exemple) and so on.

The problem is that the condition is triggered only once and if I check the flag status it stay at '1'. The setUserFlag scheduled function seems to be executed (because if I put intentionaly wrong parameters DCS complains) but the flag is not set to 0 as I would expect...

Any idea about what is going wrong ?

Thanks

Edited by CougarFFW04
Posted (edited)

Still problem.

Obviously because of my silly former error the scheduleFunction was not execute.

Now it is but with the "usual" foolowing syntaxe DCS complains (user flag name) missed

timer.scheduleFunction(trigger.action.setUserFlag,{'switchFlag',0}, timer.getTime() + 2)

tried with {switchFlag,0}, {'switchFlag',0}, {"switchFlag",0} but DCS still conplains about user falg name..

Any idea ? Should I have a coffe... LOL

Edit : I think that the problem is that the setuserFlag DCS function wants 2 parameters (not a table) but we can transmit only one (or several as a table) with the scheduleFunction. Am I wrong ? Any workaround solution? The obviuos solution would be to define my own setUserFlag function with a table as parameters and then calling the DCS native function with the 2 parameters. Sounds silly to have to do that

Edited by CougarFFW04
Posted
10 hours ago, CougarFFW04 said:

...Any idea ? Should I have a coffe... LOL...

I don't know. It should work the way you wrote it but obviously it doesn't.

I never use timer.scheduleFunction so I can't tell if there is a bug or a typo, I use the Mist function, and the following works (with Mist loaded) :

mist.scheduleFunction(trigger.action.setUserFlag, {'switchFlag',0}, timer.getTime() + 2)

 

  • 1 year later...
Posted (edited)

Probably way too late to the party, but I've solved calling the function with multiple arguments with on-site function call like this:

function dunlib.messageAll(msg, duration, clearView)
    trigger.action.outText(msg or 'Undefined message', duration or 10, clearView or false)
end

function dunlib.messageAllDelayed(msg, delay, duration, clearView)
    timer.scheduleFunction(function() dunlib.messageAll(msg, duration, clearView) end, {}, timer.getTime() + delay)
end

The first function just prints the message, and the second one does it with a delay and calls the first one with function() ... end construct, not using the second argument {} at all.

Edited by virgo47
  • Like 1
  • Thanks 1

✈️ L-39, F-4E, F-5E, F-14, F/A-18C, MiG-15, F-86F, AJS-37, C-101, FC2024 🛩️ Yak-52, P-47, Spitfire, CE2 🚁 UH-1H, Mi-8, Ka-50 III, SA342 🗺️ NTTR, PG, SY, Chnl, Norm2, Kola, DE 📦 Supercarrier, NS430, WWII, CA 🕹️ VKB STECS+Gladiator/Kosmosima+TPR ▶️ DCS Unscripted YouTube 🐛 "Favourite" bugs: 1) Object local camera fast/slow inverted, 2) Yak-52 toggles not toggling, 3) all Caucasus ATC bugs

  • Recently Browsing   0 members

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