Jump to content

Recommended Posts

Posted

I'm using timer.scheduleFunction in DCS 1.5.4 stable, but it doesn't seem to be working beyond the first call.. in other words, it's calling the function once after the delay (e.g. 5 seconds), but never again.

 

For example, a code snippet used in a "ONCE" trigger, using "TIME MORE (2)", in a DO SCRIPT (and tried it in a DO SCRIPT FILE, same result):

 

local function testFunction(time)
...
trigger.action.outText("sample text", 20)
...
return time + 5
end

do 
timer.scheduleFunction(testFunction, nil, timer.getTime() + 5)
end

 

When I load the mission, the outText output is shown after 5 seconds, but never again, so it appears the function is not being called every 5 seconds. Is there something I'm missing?

 

Thanks

Posted

You are only telling it to run once. The timer.scheduleFunction() must be run each time you want to schedule a new function to run again. It doesn't auto reschedule like the mist function can.

 

local function testFunction()

trigger.action.outText("sampleText", 20)

timer.scheduleFunction(testFunction, nil, timer.getTime() + 5)

return end

 

testFunction()

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

Interestingly (not sure if it's supposed to work this way), I found an example where it seemed they were using timer.scheduleFunction to repeatedly call a function (as opposed to just once) and all they had different was an extra unused parameter in the to-be-called function:

 

local function testFunction([color="Red"]arg[/color], time)
...
trigger.action.outText("sample text", 20)
...
return time + 5
end

do 
timer.scheduleFunction(testFunction, nil, timer.getTime() + 5)
end

 

When I added this extra parameter, the timer.scheduleFunction started repeatedly calling the function every 5 seconds (got the repeated outText messages) when I tested it offline (i.e. as a mission, not via multiplayer).

Posted

Same as 609_Relentov, I always use this kind of structure to repeat functions and that works well:

 

function repeatedfunction()
--[[
content
--]]
return timer.getTime() + 10
end	
timer.scheduleFunction(repeatedfunction, nil, timer.getTime() + 3)

 

Did I miss something?

[sIGPIC][/sIGPIC]

 

Unsere Facebook-Seite

Posted
Did I miss something?

Nope, you're doing it right. You definitely don't need to call timer.scheduleFunction() every time within your scheduled function, the return value will re-schedule it automatically (or not, if you return nil).

 

The OP's issue is they only had the one parameter:

 

local function testFunction(time)

but the timer function calls it with two: func(uservalue, time).

 

The user value being passed to the function was nil, so their return value:

return time + 5

was becoming

return nil + 5

which won't work; so the function is never called again.

  • Like 1
Posted

Thanks nomdeplume, it makes sense now, I think I just missed that in the prototype for timer.scheduleFunction it's expecting two parameters in the called function. I had thought the return value was supposed to reschedule the function, thus my confusion.

  • Recently Browsing   0 members

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