Page 1 of 1

How can I refer to an GuiElement without listing all its child names?

Posted: Tue Nov 06, 2018 3:16 pm
by WIZ4
Instead of this:

Code: Select all

function on_click(event)
	local name = event.element.name

	for i, str in pairs(global.whatever) do
	if name == 'button'..i then 
	player.gui.center.frame_1.frame_2.frame_3.flow['button'..i].enabled = false
	end
	end
end
Something like that:

Code: Select all

function on_click(event)
	local name = event.element.name

	for i, str in pairs(global.whatever) do
	if name == 'button'..i then 
	event.element.name.enabled = false
	end
	end
end
I saw that there is "children" and "children_names", but I do not know how to use them.

Re: How can I refer to an GuiElement without listing all its child names?

Posted: Tue Nov 06, 2018 3:35 pm
by DaveMcW

Code: Select all

function on_click(event)
  event.element.enabled = false
end

Re: How can I refer to an GuiElement without listing all its child names?

Posted: Tue Nov 06, 2018 3:44 pm
by WIZ4
DaveMcW wrote: Tue Nov 06, 2018 3:35 pm

Code: Select all

function on_click(event)
  event.element.enabled = false
end
Thanks!

Re: How can I refer to an GuiElement without listing all its child names?

Posted: Tue Nov 06, 2018 5:03 pm
by WIZ4
I would like to ask again. Is there a simplified method for calling other elements if they are in another function?
Such as how to reduce it?

Code: Select all

game.print(player.gui.center.frame_1.frame_2.frame_3.flow1.radiobutton.state)

Re: How can I refer to an GuiElement without listing all its child names?

Posted: Tue Nov 06, 2018 5:13 pm
by eradicator
Store the references of frequently used elements:

Code: Select all

global.blahblah = {radiobutton = player.gui.center.frame_1.frame_2.frame_3.flow1.radiobutton}
game.print(global.blahblah.radiobutton.state)
Can also be compared:

Code: Select all

local function on_event(event)
  if event.element == global.blahblah.radiobutton then
    game.print(event.element.state)
    end
  end