0.16.51 itemStack is valid but not always ..

Place to get help with not working mods / modding interface.
Post Reply
mophydeen
Filter Inserter
Filter Inserter
Posts: 529
Joined: Sun Nov 22, 2015 5:02 pm
Contact:

0.16.51 itemStack is valid but not always ..

Post 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.

Bilka
Factorio Staff
Factorio Staff
Posts: 3133
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: 0.16.51 itemStack is valid but not always ..

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.


Post Reply

Return to “Modding help”