[0.12.33;mod API] LuaItemStack.blueprint_icons
Posted: Tue May 17, 2016 8:39 pm
I don't know if this is a bug or not, but the LuaItemStack.blueprint_icons array is empty for my blueprints that only use one icon.
www.factorio.com
https://forums.factorio.com/
Code: Select all
index :: uint: Index of the icon in the blueprint icons slots. Has to be in {1, 2, 3, 4}.
Just so I understand this correctly, calling .index on blueprint_icons[3] should actually return 4? (and #blueprint_icons also returns 3, although it has 4 icons?)Rseding91 wrote:http://i.imgur.com/lSXFbrm.jpg
It looks correct to me. The index key is correct and it has 1 item in the table returned.
Yes, the reason being: you can end up with blueprints that have icons set for slots 2, and 4. That means the blueprint would have 2 icons but technically the icons are in index 2 and 4 of the blueprint. It's a little confusing but that's just currently how the blueprint icon system works.daniel34 wrote:Just so I understand this correctly, calling .index on blueprint_icons[3] should actually return 4? (and #blueprint_icons also returns 3, although it has 4 icons?)Rseding91 wrote:http://i.imgur.com/lSXFbrm.jpg
It looks correct to me. The index key is correct and it has 1 item in the table returned.
Code: Select all
local l_player = game.players[event.element.player_index]
local s_stack = l_player.cursor_stack
...
if s_stack and s_stack.valid_for_read and s_stack.type == "blueprint" and s_stack.is_blueprint_setup() then
...
if #s_stack.blueprint_icons > 0 then
local icon_quad = l_schematic.add{type="table", name="icons", colspan=2, style="slot_table_style"}
for ii, iv in ipairs(s_stack.blueprint_icons) do
icon_quad.add{type="button", name="icon_"..iv.name, style="bpr_gs_"..iv.name.."_small"}
end
else
l_schematic.add{type="label", name="icons", caption="WTF"}
end
...
end
Code: Select all
for ik, iv in pairs(s_stack.blueprint_icons) do
icon_quad.add{type="button",
name="icon_"..iv.name,
style="bpr_gs_"..iv.name.."_small"}
end
Just don't ever use ipairs... ever. There's no reason to use it over pairs and in fact In 0.13 it won't work on some of the returned collections from Factorio's API.AenAllAin wrote:... Solution:
I just switched it to a standard "pairs" for loop (even though it is supposed to be an array ), and it works.So for me, I guess problem solved although you Devs may feel different; at least there is a workaround.Code: Select all
for ik, iv in pairs(s_stack.blueprint_icons) do icon_quad.add{type="button", name="icon_"..iv.name, style="bpr_gs_"..iv.name.."_small"} end
...this did bring a different issue to light though, but I will make a separate thread for that potential bug.