Page 1 of 1

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

Posted: Sat Nov 09, 2024 8:14 am
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/

Re: Please add LuaRecord.active_index and LuaItemCommon.contents

Posted: Sat Nov 09, 2024 8:15 am
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!

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

Posted: Wed Nov 20, 2024 8:22 pm
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.