This is for medium-advanced SCAR coders. The goal is to pass parameters to a function that is started by a Rule.
One of the drawback of rules is apparently you can't call them with params. You have to create a specific function when you want something to be done after some delay.
Truth is it is possible to add parameters to rules because of some LUA particularities with local datas.
Add the following code to your SCAR code.
This function works the same way than Rule_AddOneShot() but it allows params in any number to be transfered.Code:function Rule_AddOneShotPar( LuaFunction, Delay, ...) local RuleCall=function() LuaFunction(unpack(arg)) end Rule_AddOneShot(RuleCall,Delay) end
Basic example: Rule_AddOneShotPar( print, 2, "Hello")
Another example is to delay a FX. If we want to call a titan_explosion FX in 2 seconds then it can be done with :
Rule_AddOneShotPar( World_FXEvent, 2, "DATA:Art/events/titan_explosions", Util_ScarPos(0,0) )
Any functions (hard coded or SCAR) can be called this way.
Note that there are three drawbacks:
- functions are lost on reload. The rule will not restart on reload, you will get a warning (not an error) stating that function was not found and that rule could not be restarted.
- be carefull with tables. They are duplicated when it is string or numbers but NOT for tables. Altering the table will change the rule execution. I am not even mentioning objects...
- debug can be a bit tricky especially if you play with tables.
The two first drawbacks can be worked-around but the function will get much more complex.
I have the feeling this could be useful to some. What do you think of it?



