609_Relentov Posted July 10, 2016 Posted July 10, 2016 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
Grimes Posted July 10, 2016 Posted July 10, 2016 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 Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
609_Relentov Posted July 10, 2016 Author Posted July 10, 2016 Ah, I didn't realize it didn't reschedule :). Oops - thanks for the head's up Grimes. I thought the timer version rescheduled like your Mist function
Grimes Posted July 10, 2016 Posted July 10, 2016 There is a reason Speed wrote the mist version the way he did. Also that its mostly ported from slmod anyways. ^_^ The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
609_Relentov Posted July 12, 2016 Author Posted July 12, 2016 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).
SNAFU Posted July 12, 2016 Posted July 12, 2016 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
nomdeplume Posted July 12, 2016 Posted July 12, 2016 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 + 5was becoming return nil + 5which won't work; so the function is never called again. 1
609_Relentov Posted July 12, 2016 Author Posted July 12, 2016 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.
Recommended Posts