Hi, I tried to add game.onevent stuff to another file outside control.lua and require said file, but nothing happens.
Same thing when I tried game.player.print("blah").
For everything else, like having the gui created and destroyed, works just fine. It just had to be called from inside control.lua.
Any idea why it works like that or what I am doing wrong?
Control.lua
Re: Control.lua
I think you can only hook onto an event once. What I do is hook onto all the events in control.lua and then forward any events on to functions defined in other files.
Re: Control.lua
That isn't what I did. I hooked up the event only once in files other than the control.lua.ljdp wrote:I think you can only hook onto an event once. What I do is hook onto all the events in control.lua and then forward any events on to functions defined in other files.
Re: Control.lua
Posting the relevant parts of control.lua and the other files would be helpful.
I know that Alphamod does what you want, it requires its scripts/EventHandler.lua in control.lua and registers/handles the events there.
I know that Alphamod does what you want, it requires its scripts/EventHandler.lua in control.lua and registers/handles the events there.
Re: Control.lua
The trouble is...I already moved on. Might try again later and see if it's just me.Choumiko wrote:Posting the relevant parts of control.lua and the other files would be helpful.
I know that Alphamod does what you want, it requires its scripts/EventHandler.lua in control.lua and registers/handles the events there.
Re: Control.lua
Ok, let try this:
I moved this block of code to a file called gui.lua:
But then the event stuff stopped working.
This is how I load gui.lua:
I moved this block of code to a file called gui.lua:
Code: Select all
game.onevent(defines.events.onguiclick, function(event)
local element = event.element
log("Clicked element: "..element.name)
if element.name == "repair_button" then
initializeRepairStatus()
elseif element.name == "close" then
destroyWindow()
end
end)
This is how I load gui.lua:
Code: Select all
require("gui")
Re: Control.lua
You still didn't post the relevant functions.
Try this, no extra functions at all:
Try this, no extra functions at all:
Code: Select all
game.onevent(defines.events.onguiclick, function(event)
local element = event.element
game.players[1].print("Clicked element: "..element.name)
end)