Refresh logistic chest filter while GUI is opened

Place to get help with not working mods / modding interface.
Honktown
Smart Inserter
Smart Inserter
Posts: 1058
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Refresh logistic chest filter while GUI is opened

Post by Honktown »

I made a quick test command that sets a logistic storage chests filter to the item in the first slot:

Code: Select all

/c

global.chest = nil

local function watch_and_filter_first_slot(event)
  local inv = nil
  local item = nil
  if (event.tick % 30) ~= 0 then
    do return end
  end

  if global.chest and global.chest.valid then
    inv = global.chest.get_inventory(defines.inventory.chest)
    if inv and inv.valid then
      item = inv[1]
      if item and item.valid_for_read then
        item = item.name
        global.chest.storage_filter = game.item_prototypes[item]
      end
    end
  end
end


local function add_chest_to_ticker(event)
  if event.entity and event.entity.name == "logistic-chest-storage" then
    global.chest = event.entity
  end

  script.on_event(defines.events.on_tick, watch_and_filter_first_slot)
end

local function remove_chest_from_ticker(event)
  global.chest = nil
  script.on_event(defines.events.on_tick, nil)
end

script.on_event(defines.events.on_gui_opened, add_chest_to_ticker)

script.on_event(defines.events.on_gui_closed, remove_chest_from_ticker)
Result:
chest_filter.png
chest_filter.png (29.28 KiB) Viewed 651 times
Looks like it doesn't work, right?

However:
peekaboo.png
peekaboo.png (526.46 KiB) Viewed 651 times
Peekaboo! There it is! I looked at LuiGui and LuaGuiElement, and also LuaEntity, but I don't see anything to "refresh"/update a GUI window. Only other option might be to close and re-open the GUI, preferably at the same position?
I have mods! I guess!
Link
Honktown
Smart Inserter
Smart Inserter
Posts: 1058
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Refresh logistic chest filter while GUI is opened

Post by Honktown »

I decided to do it on mouse hover, after a time-out, instead. Probably a better idea anyway. Thanks for anyone looking, I'll still be watching the thread.
I have mods! I guess!
Link
Post Reply

Return to “Modding help”