What is game.player.opened [done]

Place to get help with not working mods / modding interface.
Post Reply
matjojo
Filter Inserter
Filter Inserter
Posts: 337
Joined: Wed Jun 17, 2015 6:08 pm
Contact:

What is game.player.opened [done]

Post by matjojo »

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
Last edited by matjojo on Sun Sep 27, 2015 5:51 pm, edited 2 times in total.

User avatar
ThaPear
Fast Inserter
Fast Inserter
Posts: 226
Joined: Fri May 30, 2014 8:05 am
Contact:

Re: function called when entity is opened

Post by ThaPear »

The only way I can think of is to check player.opened every tick/few ticks and do things whenever it changes.

matjojo
Filter Inserter
Filter Inserter
Posts: 337
Joined: Wed Jun 17, 2015 6:08 pm
Contact:

Re: function called when entity is opened

Post by matjojo »

ThaPear wrote:The only way I can think of is to check player.opened every tick/few ticks and do things whenever it changes.
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!

matjojo
Filter Inserter
Filter Inserter
Posts: 337
Joined: Wed Jun 17, 2015 6:08 pm
Contact:

Re: function called when entity is opened

Post by matjojo »

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:

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
Does not work, It give this error:
Error wrote:'5' attempt to index global 'game' A nill value
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( :D ) 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?

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.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: function called when entity is opened

Post by prg »

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!

matjojo
Filter Inserter
Filter Inserter
Posts: 337
Joined: Wed Jun 17, 2015 6:08 pm
Contact:

Re: function called when entity is opened

Post by matjojo »

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.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: function called when entity is opened

Post by prg »

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!

matjojo
Filter Inserter
Filter Inserter
Posts: 337
Joined: Wed Jun 17, 2015 6:08 pm
Contact:

Re: function called when entity is opened

Post by matjojo »

prg wrote:What made you think requiring control.lua from data.lua would be a good idea? It certainly doesn't belong in there.
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.

matjojo
Filter Inserter
Filter Inserter
Posts: 337
Joined: Wed Jun 17, 2015 6:08 pm
Contact:

What is game.player.opened

Post by matjojo »

ThaPear wrote:The only way I can think of is to check player.opened every tick/few ticks and do things whenever it changes.
So, now I have this:

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)
but every time I open the energy condenser it just says "its something else". And if nothing is opened (obviously) it says "its still nil" so I have tried a load of different things that game.player.opened might be, but I can't figure it out. The wiki says this:
Lua/Entity The entity that owns the GUI the player currently has open. Nil if none.
So the wiki didn't really tell much for use (for me).

my entities.lua contains this: (snippet)

Code: Select all

type = "container",
    name = "energy-condenser",
So what actually is stored in game.player.opened?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13254
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: What is game.player.opened

Post by Rseding91 »

The LuaEntity object that was opened.
If you want to get ahold of me I'm almost always on Discord.

matjojo
Filter Inserter
Filter Inserter
Posts: 337
Joined: Wed Jun 17, 2015 6:08 pm
Contact:

Re: What is game.player.opened

Post by matjojo »

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.

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: What is game.player.opened

Post by ratchetfreak »

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.

matjojo
Filter Inserter
Filter Inserter
Posts: 337
Joined: Wed Jun 17, 2015 6:08 pm
Contact:

Re: What is game.player.opened

Post by matjojo »

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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13254
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: What is game.player.opened

Post by Rseding91 »

matjojo 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.
Because it's the LuaEntity: https://forums.factorio.com/wiki/inde ... Lua/Entity

It's a reference to the entity opened.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5152
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: What is game.player.opened

Post by Klonan »

you need to call the 'if' on not the entity, but the entities name

so in your case you would go

Code: Select all

if a.name =="energy-condenser" then game.players[1]print("Found condensor")

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: What is game.player.opened

Post by ratchetfreak »

matjojo 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.
sorry I forgot to add the ".name" after pasting

matjojo
Filter Inserter
Filter Inserter
Posts: 337
Joined: Wed Jun 17, 2015 6:08 pm
Contact:

Re: What is game.player.opened

Post by matjojo »

ratchetfreak wrote:
matjojo 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.
sorry I forgot to add the ".name" after pasting
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)

Post Reply

Return to “Modding help”