Page 1 of 1

Help (Access to blueprint-book)

Posted: Sun Jul 10, 2016 8:32 pm
by Tanatos
Primitive code without further checks.

Code: Select all

-- blueprint-book. Item 1,2 and 8 real blueprint
local cursor_stack = player.cursor_stack
-- Active Item in Book. Get blueprint: "item_active[1]"
local item_active = cursor_stack.get_inventory(defines.inventory.item_active)
-- Stored Items in Book. Get blueprint: "item_main[1..30]" 
local item_main = cursor_stack.get_inventory(defines.inventory.item_main)
-- Real blueprint`s in Book (without active)
local Count = item_main.get_item_count("blueprint")
-- Size of Book, default 30
local Size = #item_main

item_main[1].valid -- Ok
item_main[1].label -- Ok
item_main[2].valid -- Ok
item_main[2].label -- Ok

item_main[3].valid -- Ok
item_main[3].label -- Error: "LuaItemStack API call when LuaItemStack was invalid."
-- How check!?
--
item_main[8].valid -- Ok
item_main[8].label -- Ok
How to check the item in the book: it is empty or not? For example, the book contains a valid blueprint 1, 2 and 8 slots.

All 30 elements return true for checking "item_main [2] .valid"
Elements 1,2 and 8 are LuaItemStack, you can call the "name", "label", etc.
All other elements generate an error when calling "LuaItemStack API call when LuaItemStack was invalid."

Re: Help (Access to blueprint-book)

Posted: Sun Jul 10, 2016 8:38 pm
by prg
Use .valid_for_read instead of .valid.

Re: Help (Access to blueprint-book)

Posted: Sun Jul 10, 2016 8:41 pm
by Tanatos
Working! Thank you for your prompt response.