Custom sprite-button not firing on_gui_click

Place to get help with not working mods / modding interface.
Post Reply
NindyBun
Burner Inserter
Burner Inserter
Posts: 7
Joined: Wed Apr 14, 2021 6:45 am
Contact:

Custom sprite-button not firing on_gui_click

Post by NindyBun »

I made a "sprite-button" that displays the item icon with related tooltips but the button doesn't fire the on_gui_click event when pressed.
Everything but the button registers the click event
Everything but the button registers the click event
button.PNG (675.07 KiB) Viewed 656 times
https://github.com/NindyBun/RefinedNetw ... e.lua#L277

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5151
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Custom sprite-button not firing on_gui_click

Post by Klonan »

Are you setting the mouse filter on the button? https://lua-api.factorio.com/latest/Lua ... ton_filter

NindyBun
Burner Inserter
Burner Inserter
Posts: 7
Joined: Wed Apr 14, 2021 6:45 am
Contact:

Re: Custom sprite-button not firing on_gui_click

Post by NindyBun »

Klonan wrote:
Thu Jul 27, 2023 10:18 am
Are you setting the mouse filter on the button? https://lua-api.factorio.com/latest/Lua ... ton_filter
Looking at the function I use to make the button, I don't think I set the mouse filter anywhere. It's also the same function I used to make the 'X' close button on the window and that works fine.

Code: Select all

function GuiApi.add_button(guiTable, name, gui, sprite, hoverSprite, clickedSprite, tooltip, size, save, visible, count, style, tags)
    if visible == false then return end
    if name ~= nil and name ~= "" and guiTable.vars[name] ~= nil then guiTable.vars[name].destroy() end
    local button = gui.add{type="sprite-button", name=name, sprite=sprite, hovered_sprite=hoverSprite, clicked_sprite=clickedSprite, resize_to_sprite=false, tooltip=tooltip, number=count, tags=tags}
    if style ~= nil then button.style = style end
    button.style.minimal_width = size
    button.style.maximal_width = size
    button.style.minimal_height = size
    button.style.maximal_height = size
    button.style.padding = 0
    button.style.margin = 0
    if guiTable ~= nil and save == true then
        guiTable.vars[name] = button
    end
    return button
end
I went ahead and put the filter to see if that solves the problem but it still doesn't.

NindyBun
Burner Inserter
Burner Inserter
Posts: 7
Joined: Wed Apr 14, 2021 6:45 am
Contact:

Re: Custom sprite-button not firing on_gui_click

Post by NindyBun »

Okay, I've narrowed the issue to the guiElement#clear function. I have a scroll pane that clears every second and then redraws the necessary guiElements because I need it to refresh. It turns out that if I don't use the clear function, the buttons fire the on_click_event which is great but I need to clear the elements though...

Rseding91
Factorio Staff
Factorio Staff
Posts: 13236
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Custom sprite-button not firing on_gui_click

Post by Rseding91 »

NindyBun wrote:
Fri Jul 28, 2023 10:11 am
Okay, I've narrowed the issue to the guiElement#clear function. I have a scroll pane that clears every second and then redraws the necessary guiElements because I need it to refresh. It turns out that if I don't use the clear function, the buttons fire the on_click_event which is great but I need to clear the elements though...
Store the elements you created and update them as things change. Deleting and re-creating them is not needed.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding help”