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?
[solved] GUI elements - how to determine type?
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
[solved] GUI elements - how to determine type?
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.
Re: GUI elements - how to determine type?
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 

- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: GUI elements - how to determine type?
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.
Re: GUI elements - how to determine type?
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
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
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: GUI elements - how to determine type?
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.