Page 1 of 1

0.16.51 itemStack is valid but not always ..

Posted: Tue Sep 25, 2018 12:01 pm
by mophydeen
Construction robots:

Code: Select all

	
local itemStack = robot.get_inventory(defines.inventory.robot_cargo)[1]
if itemStack and itemStack.valid then
	if not player.can_insert(itemStack) then
		player.print("full")
		fish_market_temp_increase_inventory_bonus(player)
	end
	player.insert(itemStack)
end
If I let the c-robot build something, it has that item in it's stack: everything works

If i let the c-robot repair something, it has nothing in the cargo stack: it crashes @ can_insert, while it should have been stopped at nil or .valid
Error while running event level::on_gui_click (ID 1)
LuaItemStack API call when LuaItemStack was invalid.
stack traceback:
[C]: in function 'can_insert'
...temp/currently-playing/1337_toggle_personal_roboport.lua:83: in function 'remove_robots'
...temp/currently-playing/1337_toggle_personal_roboport.lua:133: in function 'update'
...temp/currently-playing/1337_toggle_personal_roboport.lua:153: in function 'toggle_personal_roboport_on_gui_click'
/home/sl/.factorio/temp/currently-playing/control.lua:92: in function </home/sl/.factorio/temp/currently-playing/control.lua:83>
Thank you


note: I do know there is more than 1 inventory, not the point.

Re: 0.16.51 itemStack is valid but not always ..

Posted: Tue Sep 25, 2018 12:17 pm
by Bilka
An itemstack can be valid even when empty, use https://lua-api.factorio.com/latest/Lua ... d_for_read to make sure it's not empty.

Re: 0.16.51 itemStack is valid but not always ..

Posted: Tue Sep 25, 2018 12:37 pm
by mophydeen
thank you