Issues
while creating my mod i ran into some inconsistencies.LuaRecord and LuaItemStack expose mostly the same modding interface, but there are some jarring differences.
- LuaRecord
- 'name' field is missing. Should be prototype name.
- 'type' field gives prototype name. Should be prototype type.
- 'valid_for_read' field is missing. Should be bool.
- LuaItemStack
- 'valid_for_write' field is missing. Should be bool.
- 'contents' field is missing for blueprint books. Should be array[LuaItemStack].
How to reproduce/test
- load the supplied example save with some prepared books and planners. Or create some yourself.
- execute the following command.
Code: Select all
/c local function dump(v) local t = serpent.serialize(v,{comment=false,sortkeys=false,sparse=true,compact=true,indent="\t"}) for _,p in pairs(game.connected_players) do p.print(t,{game_state=false,skip=defines.print_skip.never}) end return log(t) end local function getter(t,k) return t[k] end local function get(t,k) local _,r = pcall(getter,t,k) return r==nil and "nil" or r end script.on_event(defines.events.on_player_cursor_stack_changed,function(ev) local p = game.get_player(ev.player_index) local i = p.cursor_record or p.cursor_ghost or (p.cursor_stack.valid_for_read and p.cursor_stack) if not i then return end return dump{ hand = i, item = { name = get(i,"name"), type = get(i,"type"), valid_for_read = get(i,"valid_for_read"), valid_for_write = get(i,"valid_for_write"), contents = get(i,"contents"), }, } end)
- picking up planners and books gives output like this in con, log and chat.
Code: Select all
hand="[LuaItemStack: 1x {deconstruction-planner, normal}]", item={ name="deconstruction-planner", type="deconstruction-item", valid_for_read=true, valid_for_write="LuaItemStack doesn't contain key valid_for_write.", contents="LuaItemStack doesn't contain key contents." } hand="[LuaRecord: deconstruction planner ID=2 in game shelf]", item={ name="LuaRecord doesn't contain key name.", type="deconstruction-planner", valid_for_read="LuaRecord doesn't contain key valid_for_read.", valid_for_write=true, contents="Record is not a BlueprintBookRecord." } hand="[LuaItemStack: 1x {blueprint-book, normal}]", item={ name="blueprint-book", type="blueprint-book", valid_for_read=true, valid_for_write="LuaItemStack doesn't contain key valid_for_write.", contents="LuaItemStack doesn't contain key contents." } hand="[LuaRecord: book ID=22 inside of a book ID=18 inside of a book ID=8 in game shelf]", item={ name="LuaRecord doesn't contain key name.", type="blueprint-book", valid_for_read="LuaRecord doesn't contain key valid_for_read.", valid_for_write=true, contents={ "[LuaRecord: blueprint ID=23 inside of a book ID=22 inside of a book ID=18 inside of a book ID=8 in game shelf]", "[LuaRecord: deconstruction planner ID=24 inside of a book ID=22 inside of a book ID=18 inside of a book ID=8 in game shelf]", "[LuaRecord: upgrade planner ID=25 inside of a book ID=22 inside of a book ID=18 inside of a book ID=8 in game shelf]", "[LuaRecord: book ID=26 inside of a book ID=22 inside of a book ID=18 inside of a book ID=8 in game shelf]" } }