Control.lua

Place to get help with not working mods / modding interface.
kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Control.lua

Post by kiba »

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?
ljdp
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Wed Jul 01, 2015 12:33 am
Contact:

Re: Control.lua

Post by ljdp »

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.
kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Re: Control.lua

Post by kiba »

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.
That isn't what I did. I hooked up the event only once in files other than the control.lua.
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Control.lua

Post by Choumiko »

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.
kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Re: Control.lua

Post by kiba »

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.
The trouble is...I already moved on. Might try again later and see if it's just me.
kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Re: Control.lua

Post by kiba »

Ok, let try this:

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)
But then the event stuff stopped working.

This is how I load gui.lua:

Code: Select all

require("gui")
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Control.lua

Post by DaveMcW »

You still didn't post the relevant functions.

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)
Post Reply

Return to “Modding help”