Page 1 of 1

How can I close a GUI without "name"?

Posted: Thu May 19, 2022 3:16 am
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()

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

Posted: Thu May 19, 2022 6:17 am
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

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

Posted: Thu May 19, 2022 8:39 am
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