on_gui_click, press/release posibility?

Place to get help with not working mods / modding interface.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: on_gui_click, press/release posibility?

Post 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
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”