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.

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

Posted: Wed Jan 01, 2025 2:18 pm
by folk
Happy new year! Please I hope you take a look at this :-)

Am I allowed to "bump" my threads like this? I sure hope so!

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

Posted: Wed Jan 29, 2025 7:51 pm
by raiguard
LuaRecord::get_active_index() was added in 2.0.29.

You can access the blueprint book item contents with LuaItemCommon::get_inventory(defines.inventory.item_main).

As for the disparity between the two APIs, they are fundamentally different things in the engine, so it is impossible to represent them identically.

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

Posted: Wed May 28, 2025 9:25 am
by livetalk
raiguard wrote: Wed Jan 29, 2025 7:51 pm You can access the blueprint book item contents with LuaItemCommon::get_inventory(defines.inventory.item_main).

As for the disparity between the two APIs, they are fundamentally different things in the engine, so it is impossible to represent them identically.
Thanks for posting this! It's currently quite difficult to figure out how to access the blueprints of a book by just looking at the modding API. Especially because it is so easy on the LuaRecord.

So

Code: Select all

LuaItemCommon::contents()
or an extended comment on

Code: Select all

LuaItemCommon::is_blueprint_book
would still be very nice to have.