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)
However: 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?