[2.0.16] Please add LuaRecord.active_index and LuaItemCommon.contents

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
folk
Fast Inserter
Fast Inserter
Posts: 100
Joined: Fri Mar 03, 2017 5:00 pm
Contact:

[2.0.16] Please add LuaRecord.active_index and LuaItemCommon.contents

Post by folk »

Hi,

So great work guys I am loving the game again :-D

Apparently I posted this in the wrong forum initially, so I'll delete that post and here it is again \o/

I just updated my mod here https://mods.factorio.com/mod/folk-janitor and with the scripting changes in 2.0.16 I really wanted to get going with the personal logistics stuff, but specifically working with blueprint books is made difficult by what I imagine is actually just something you overlooked.

I'll let past self me explain from the code: https://github.com/folknor/factorio-jan ... ol.lua#L65

Code: Select all

	-- So here's the problem with books. There are two kinds: books from inventory and books from the library.
	-- p.cursor_stack.is_blueprint_book = true for inventory, false for library
	-- p.cursor_record is valid for library, invalid for inventory
	-- both _stack and _record .type == "blueprint-book"
	--
	-- _record has a field called https://lua-api.factorio.com/latest/classes/LuaRecord.html#contents
	--     from this field we can iterate all the blueprints in the book
	-- _stack has a field called https://lua-api.factorio.com/latest/classes/LuaItemCommon.html#active_index
	--     from this field we can determine which blueprint is the active one in a book
	--
	-- But that's the problem. _record doesn't have active_index, and _stack doesn't have .contents.
	-- So we can't really work with either of them.
	-- For _record (library books) we can't actually get the contents of any of the blueprints because
	-- we can't iterate them.
	-- And for _stack we can determine the active blueprint index, but not get the contents of that
	-- blueprint by index.
And yes yes I know my code is not very optimized but it's friday night, I want to play with my cats.

\o/
Last edited by folk on Mon Nov 11, 2024 11:28 am, edited 1 time in total.
folk
Fast Inserter
Fast Inserter
Posts: 100
Joined: Fri Mar 03, 2017 5:00 pm
Contact:

Re: Please add LuaRecord.active_index and LuaItemCommon.contents

Post by folk »

Also, on a related note as you can see here https://github.com/folknor/factorio-jan ... ol.lua#L87 please consider making `local s = log.add_section("Janitor")` NOT create a new section every time but return the one that exists with the same name already?

Thanks again!
robot256
Filter Inserter
Filter Inserter
Posts: 891
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: [2.0.16] Please add LuaRecord.active_index and LuaItemCommon.contents

Post by robot256 »

+1 for LuaRecord::active_index of blueprint books. Right now it's impossible to tell what the player is using from within the book, unless we're misunderstanding something.
Post Reply

Return to “Modding interface requests”