TJTAS Posted August 15, 2022 Posted August 15, 2022 (edited) OK the documentation both on the ED site and Hoggit's world are a bit vague on the usage of timer.scheduleFunction and how to pass parameters to a function called with it. DCS official docs says:- FunctionId function timer.scheduleFunction(FunctionToCall functionToCall, any functionArgument, Time time) Hoggit's world says:- timer.scheduleFunction(main, {}, timer.getTime() + 120) What neither clearly say are that you can only pass a Single parameter to the called function. If you need to send multiple parameters to your scheduled function send them as a table and then extract the parameters from the table (in the scheduled function). Edited August 15, 2022 by TJTAS
cfrag Posted August 15, 2022 Posted August 15, 2022 3 hours ago, TJTAS said: What neither clearly say are that you can only pass a Single parameter to the called function TBH, the definition is syntactically and semantically correct: a single parameter that can be any Lua type, and that is intended to be passed as argument to the function to invoke later. In Lua, a variable number of parameters are indicated by "...", and that does not appear in scheduleFunction's definition. The choice of the word 'any' may be problematic for some people reading it, though, as this it could imply something that it is not, and may have run counter to some people's expectations: as mentioned above, arg vectors can be passed in Lua and it's common to do so in generic function schedulers. If ED exchanged the order for the parameters "time" and "args", args could have been a variable number of parameters type. That would probably have been a more useful definition. So the current definition of 'any' excludes this possibility; it is correct and not vague at all. Perhaps superficially misleading
Chump Posted August 15, 2022 Posted August 15, 2022 any functionArgument This could mean a single variable, or a single object/table. Examples: timer.scheduleFunction(myMethod, playerName, timer.getTime() + 1) -- single variable value timer.scheduleFunction(myMethod, { name = "Test", id = 0 }, timer.getTime() + 1) -- object containing multiple variable values tiemr.scheduleFunction(myMethod, {}, timer.getTime() + 1) -- nothing passed into myMethod tiemr.scheduleFunction(myMethod, nil, timer.getTime() + 1) -- nothing passed into myMethod
TJTAS Posted August 15, 2022 Author Posted August 15, 2022 Well to me the important bit which was not apparent to me (and others based on questions here) was that the Function which is scheduled can only have a single parameter and if it's a table then the receiving function has to interpret it so.
Recommended Posts