Hello Im fairly new to factorio mod development (but not programming in general). Im looking to make a small mod that interacts with the logistic trash slot. My problem is I'm not sure how to get access to the items in the trash slots
I've figured out how to access the main inventory with `player.get_main_inventory()` but I can't find anything specific to the trash slots on the docs. Maybe I'm just overlooking it?
Side note: Is there a better way to find the max non-nil logistic request slot_index? My solution is just to keep trying until the last 10-ish slots have been nil but that isn't a nice solution
Access content of trash slots
-
- Burner Inserter
- Posts: 7
- Joined: Thu Jun 04, 2020 5:33 pm
- Contact:
Re: Access content of trash slots
You can use LuaControl::get_inventory:Summoner99 wrote: ↑Wed Aug 07, 2024 4:14 pmI've figured out how to access the main inventory with `player.get_main_inventory()` but I can't find anything specific to the trash slots on the docs. Maybe I'm just overlooking it?
Code: Select all
local trash
local character = player and player.valid and player.character
if character and character.valid then
trash = character.get_inventory(defines.inventory.character_trash)
end
You can use LuaForce::character_trash_slot_count for the character trash slots that every player on the force has, and LuaControl::character_trash_slot_count_bonus for the bonus trash slots a given character may have.Side note: Is there a better way to find the max non-nil logistic request slot_index? My solution is just to keep trying until the last 10-ish slots have been nil but that isn't a nice solution
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
-
- Burner Inserter
- Posts: 7
- Joined: Thu Jun 04, 2020 5:33 pm
- Contact:
Re: Access content of trash slots
Thank you so much! That will help with exactly what I need to do.
The second point about finding the "max non-nil logistic request slot_index" was specifically referring to the logistic request slots, not the trash slots. Thats fine though. My solution incurs a negligible performance hit so Im not worried about it
The second point about finding the "max non-nil logistic request slot_index" was specifically referring to the logistic request slots, not the trash slots. Thats fine though. My solution incurs a negligible performance hit so Im not worried about it
Re: Access content of trash slots
Ooops, sorry! My mind was set on trash, so I didn't notice you wanted logistics.Summoner99 wrote: ↑Wed Aug 07, 2024 5:27 pmThe second point about finding the "max non-nil logistic request slot_index" was specifically referring to the logistic request slots, not the trash slots. Thats fine though. My solution incurs a negligible performance hit so Im not worried about it
Anyway, you can get the index of the last non-nil slot with LuaEntity::request_slot_count. However, you should note that you can't use this with LuaPlayer, but only with a character!
Code: Select all
local char = player.character
if char and char.valid then
local max_slot = char.request_slot_count
end
Code: Select all
local logistics_enabled = player.character_personal_logistic_requests_enabled
local char = player.character
if logistics_enabled and char and char.valid then
local max_slot = char.request_slot_count
end
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!