I made some good progress with it, but now I am stuck at the onguiclick event.
It is quite big (nearly 500 lines), I guess I can move some of the code into seperate functions, but in the end it will still look like:
Code: Select all
game.onevent(defines.events.onguiclick, function(event)
if event.element.name == "button_1" then ...
elseif event.element.name == "button_2" then ...
elseif event.element.name == "button_3" then ...
...
elseif event.element.name == "button_100000" then ...
So my question is, is there a smarter/cleaner way than the huge if-then-else construct?
EDIT: What I am thinking about is something like this:
Code: Select all
game.onevent(defines.events.onguiclick, function(event)
if event.element.highestParent == "Frame_A" then foo(event.element.name)
elseif event.element.highestParent == "Frame_B" then bar(event.element.name)
...
end
Obviously this will not result in less code, but would allow me to move all "button"-codes that belongs to the same UI into seperate functions, which makes it easier to maintain, IMO.