What is game.player.opened [done]
What is game.player.opened [done]
I am working on the new version of Equivalent Exchange(EE2), I need to make a GUI when an entity(container) is opened, I found the mod Galactic Trade which does this but could not figure out how he/she does it.
Is there some Function like game.on_init to use when wanting to achieve the discussed result?
Or is there another thing I could do?
As usual I'm open for giving extra information.
matjojo
Is there some Function like game.on_init to use when wanting to achieve the discussed result?
Or is there another thing I could do?
As usual I'm open for giving extra information.
matjojo
Last edited by matjojo on Sun Sep 27, 2015 5:51 pm, edited 2 times in total.
Re: function called when entity is opened
The only way I can think of is to check player.opened every tick/few ticks and do things whenever it changes.
My mods: Red Alert Harvesters - Clean Pipes - Filtered Splitters
Re: function called when entity is opened
well, thanks al lot, I didn't even think of searching this on the player side of things, I'll report back oncy I have something more to say other than thanks!ThaPear wrote:The only way I can think of is to check player.opened every tick/few ticks and do things whenever it changes.
Re: function called when entity is opened
So yeah, although the idea you had probably will work I am failing at another piece now, it probably is something really small but my code:
Does not work, It give this error:
I will be trying to delete pieces of the galactic trade mod to see which part of the code makes this work. but as always I'm open for more info.
Code: Select all
require("util")
require("defines")
--the code
game.on_event(defines.events.on_tick, function(event)
if game.player.opened == "energycondenser" then
EEisopened(1)
end
end)
function EEisopened (a)
game.player.gui.testframe.caption = "Game detected the opening of the Energy Condenser"
end
Now line 5 is the line which has game.on_event(defines.events.on_tick, function(event) on it. But, I copied this line straight outta( ) Galactic trade 0.6.4 beacuse for the Gui thing I already had downloaded that mod. But still, The code didn't work. Even if I copy the line exactly. What am I missing?Error wrote:'5' attempt to index global 'game' A nill value
I will be trying to delete pieces of the galactic trade mod to see which part of the code makes this work. but as always I'm open for more info.
Re: function called when entity is opened
Are you maybe doing this in data.lua? There would be no game available, try control.lua.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: function called when entity is opened
prg wrote:Are you maybe doing this in data.lua? There would be no game available, try control.lua.
nope, this is in control.lua
I just for a joke deleted control.lua from the require list in data.lua and the game booted, I do not remember reading about this anywhere, But it booted at least.
Re: function called when entity is opened
What made you think requiring control.lua from data.lua would be a good idea? It certainly doesn't belong in there.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: function called when entity is opened
I never actually used custom code in EE before, So I never learned how to use control.lua good enough to know, I just assumed so.prg wrote:What made you think requiring control.lua from data.lua would be a good idea? It certainly doesn't belong in there.
What is game.player.opened
So, now I have this:ThaPear wrote:The only way I can think of is to check player.opened every tick/few ticks and do things whenever it changes.
Code: Select all
game.on_event(defines.events.on_tick, function(event)
a = game.player.opened
if(a == "energy-condenser")
then
game.player.print("The game detected the opening of the energy condenser")
elseif(a == nil)
then[quote][/quote]
game.player.print("its still nil")
elseif(a == "container.energy-condenser")
then
game.player.print("its the thing in the code")
else
game.player.print("its something else")
end
end)
So the wiki didn't really tell much for use (for me).Lua/Entity The entity that owns the GUI the player currently has open. Nil if none.
my entities.lua contains this: (snippet)
Code: Select all
type = "container",
name = "energy-condenser",
Re: What is game.player.opened
The LuaEntity object that was opened.
If you want to get ahold of me I'm almost always on Discord.
Re: What is game.player.opened
Rseding91 wrote:The LuaEntity object that was opened.
yeah, but what would that be when the same of the entity opened is "energy-condenser"
note: I did try to print game.player.opened, it didn't work.
-
- Filter Inserter
- Posts: 952
- Joined: Sat May 23, 2015 12:10 pm
- Contact:
Re: What is game.player.opened
in other words a.name == "energy-condenser" will be the true
Last edited by ratchetfreak on Fri Sep 25, 2015 9:49 pm, edited 1 time in total.
Re: What is game.player.opened
ratchetfreak wrote:in other words a == "energy-condenser" will be the true
but, it does not, As said, it prints "its something else", which only gets printed if game.player.print ~= "energy-condenser" or nil.
so it is something else.
Re: What is game.player.opened
Because it's the LuaEntity: https://forums.factorio.com/wiki/inde ... Lua/Entitymatjojo wrote:Rseding91 wrote:The LuaEntity object that was opened.
yeah, but what would that be when the same of the entity opened is "energy-condenser"
note: I did try to print game.player.opened, it didn't work.
It's a reference to the entity opened.
If you want to get ahold of me I'm almost always on Discord.
Re: What is game.player.opened
you need to call the 'if' on not the entity, but the entities name
so in your case you would go
so in your case you would go
Code: Select all
if a.name =="energy-condenser" then game.players[1]print("Found condensor")
-
- Filter Inserter
- Posts: 952
- Joined: Sat May 23, 2015 12:10 pm
- Contact:
Re: What is game.player.opened
sorry I forgot to add the ".name" after pastingmatjojo wrote:ratchetfreak wrote:in other words a == "energy-condenser" will be the true
but, it does not, As said, it prints "its something else", which only gets printed if game.player.print ~= "energy-condenser" or nil.
so it is something else.
Re: What is game.player.opened
that worked, be sure never to check "if a.name == nil" that will break the game. but just checking "if a.name == "energy-condenser"" does work. (even if it is nil)ratchetfreak wrote:sorry I forgot to add the ".name" after pastingmatjojo wrote:ratchetfreak wrote:in other words a == "energy-condenser" will be the true
but, it does not, As said, it prints "its something else", which only gets printed if game.player.print ~= "energy-condenser" or nil.
so it is something else.