How can I close a GUI without "name"?

Place to get help with not working mods / modding interface.
Post Reply
sdgmlj
Fast Inserter
Fast Inserter
Posts: 127
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

How can I close a GUI without "name"?

Post by sdgmlj »

I want to close the GUI of other mods in my mod and replace it with my GUI, but his GUI doesn't have "name", so how can I close it? He wrote:
global.inserter_guis[player.index] = player.gui.relative.add{
type = "frame",
caption = { "aaaaa" },
anchor = {................ },
{................}
}
How should I write it?
player.gui.relative["?????"].destroy()

Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: How can I close a GUI without "name"?

Post by Pi-C »

sdgmlj wrote:
Thu May 19, 2022 3:16 am
I want to close the GUI of other mods in my mod and replace it with my GUI, but his GUI doesn't have "name", so how can I close it? He wrote:
global.inserter_guis[player.index] = player.gui.relative.add{
type = "frame",
caption = { "aaaaa" },
anchor = {................ },
{................}
}
How should I write it?
player.gui.relative["?????"].destroy()
I haven't used player.gui.relative yet, but usually you could do something like

Code: Select all

for e, element in pairs(player.gui.top.children) do
	game.print("Name of element "..e..": ".. element.name)
end
player.gui.relative["?????"].destroy()
Never ever do that! Why do you think you're entitled to DESTROY some other mod's GUI? You can hide it, by making it invisible, but you shouldn't destroy it:

Code: Select all

for p, player in pairs(game.players) do
	for e, element in pairs(player.gui.top.children) do
		element.visible = false
	end
end
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

sdgmlj
Fast Inserter
Fast Inserter
Posts: 127
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

Re: How can I close a GUI without "name"?

Post by sdgmlj »

Pi-C wrote:
Thu May 19, 2022 6:17 am
sdgmlj wrote:
Thu May 19, 2022 3:16 am
I want to close the GUI of other mods in my mod and replace it with my GUI, but his GUI doesn't have "name", so how can I close it? He wrote:
global.inserter_guis[player.index] = player.gui.relative.add{
type = "frame",
caption = { "aaaaa" },
anchor = {................ },
{................}
}
How should I write it?
player.gui.relative["?????"].destroy()
I haven't used player.gui.relative yet, but usually you could do something like

Code: Select all

for e, element in pairs(player.gui.top.children) do
	game.print("Name of element "..e..": ".. element.name)
end
player.gui.relative["?????"].destroy()
Never ever do that! Why do you think you're entitled to DESTROY some other mod's GUI? You can hide it, by making it invisible, but you shouldn't destroy it:

Code: Select all

for p, player in pairs(game.players) do
	for e, element in pairs(player.gui.top.children) do
		element.visible = false
	end
end
Thank you. According to your method, it succeeded.

And I admit I'm wrong. I shouldn't destroy him. I just hide him

Post Reply

Return to “Modding help”