ED Forums - View Single Post - Tutorial: Introduction to Lua scripting
View Single Post
Old 05-29-2014, 09:43 PM   #21
piXel496
Member
 
piXel496's Avatar
 
Join Date: Oct 2013
Posts: 351
Default

Quote:
Originally Posted by Joyride View Post
Short version: how to you make a function name dynamic?

Long version:

I need to create an event handler within a function, but may have several of these event handlers going concurrently for different "CAS taskings". In all of the examples I've seen event handlers are global. Thus, is there a way with lua to create a dynamic variable name for the event handler?

For example, the event handler checks for blue-on-blue shots and is called BlueDamageHandler. This is called within function "CAS_1" which has a variable "Task" (function CAS_1(Task). So, task #1 is running and calls BlueDamageHandler to start checking for blue-on-blue shots.

Meanwhile, CAS task #2 is activated using the same overall function, and also needs to call on this BlueDamageHandler but with different units to check on, etc. So how do I make the damage handler specific to each task? What I want to do is have the damage handler be called "BlueDamageHandler_01" or something for the first task, "BlueDamageHandler02" for the second, and so on.

Hi Joyride,

If I understand the idea you want to script. I think you have to keep your eventhandler global, since it wil fire on that level in in the ED-world. And you have to create the dynamic requirement to make your script behave the way you like within the eventhandler. you could make a filter within your eventhandler that distiquishes for instance "if unitSet_1 then" and "if unitSet_2 then" or "if with_as_much_flavours_as_you_like then". To make it readable you could even send each if, to there own function outside the eventhandler.





.
__________________

Last edited by piXel496; 05-29-2014 at 09:45 PM. Reason: just if
piXel496 is offline   Reply With Quote