[solved] GUI elements - how to determine type?

Place to get help with not working mods / modding interface.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

[solved] GUI elements - how to determine type?

Post by aubergine18 »

UPDATE: .type property now available on gui elements since 0.13.20

If I've got a GUI with a bunch of GUI elements in it, I can get a list of the elements and inspect their various properties, but there doesn't seem to be any quick way to determine the type of the elements... I'm trying to avoid having yet another custom lookup list to manage my GUI... Any ideas?
Last edited by aubergine18 on Mon Aug 29, 2016 10:53 pm, edited 1 time in total.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: GUI elements - how to determine type?

Post by Nexela »

LuiGuiElement seems to not have a .type property read. I wonder if this is something that the dev's might be interested in adding for us modders :)
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: GUI elements - how to determine type?

Post by aubergine18 »

I'll put in a request if there isn't already one.

viewtopic.php?f=28&t=31724
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Helfima
Fast Inserter
Fast Inserter
Posts: 202
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: GUI elements - how to determine type?

Post by Helfima »

i use string.find AND regex pattern on the GuiElement name, my MOD have a big dynamic UI

https://github.com/Helfima/helmod/blob/ ... Dialog.lua

Code: Select all

function PlannerDialog.methods:on_gui_click(event)
	if event.element.valid and string.find(event.element.name, self:classname()) then
		local player = game.players[event.player_index]
		
		local patternAction = self:classname().."=([^=]*)"
		local patternItem = self:classname()..".*=ID=([^=]*)"
		local patternItem2 = self:classname()..".*=ID=[^=]*=([^=]*)"
		local patternItem3 = self:classname()..".*=ID=[^=]*=[^=]*=([^=]*)"
		local action = string.match(event.element.name,patternAction,1)
		local item = string.match(event.element.name,patternItem,1)
		local item2 = string.match(event.element.name,patternItem2,1)
		local item3 = string.match(event.element.name,patternItem3,1)

		self:send_event(player, event.element, action, item, item2, item3)
	end
end
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: GUI elements - how to determine type?

Post by aubergine18 »

For now I've resorted to using serpent to serialise tables in to element names, and then deserialise when a gui event is triggered. A new .type property has been implemented for next release so that will make type checking much more reliable.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding help”