Page 2 of 2

Re: on_gui_click, press/release posibility?

Posted: Fri Oct 06, 2017 5:31 pm
by eradicator
Klonan wrote:Really nameless elements are best for things like labels, frames, flows, holding tables, things that you don't have to listen for directly in events
Oh, nice to know they can be compared directly. How fast is that tho, aka how bad would it be to loop through a list of elements to find the one matching pair?
And what is the actual element.name of an "unnamed" element, is it <1(int)>, <"1"(string)> or just nil?

Also i often use the names of holding tables, flows etc to see what subtable a button belongs too. E.g. if you have two tables with 10 equal buttons each and want to know which of the two tables a button is in, then i can just do something similar to this:

Code: Select all

if event.element.parent.name == 'table1_name' then
 --dostuff
else if event.element.parent.name == 'table2_name' then
 --dostuff
 end
This feels cleaner than to use string operations to try to extract the information from a prefixed button name like "mymod_maingui_table2_button1". And from my limited understanding of factorio-lua internals it should save some memory if the button's name is just "button1" instead because i don't have to create/split a ton of button names? (Many ppl "on google" suggest string creation is slow in lua.)


PS: I'm not a moderator but i think that qualifies as "don't double post" :P