Page 1 of 1

player.cursor_stack ~= nil always true?

Posted: Sat Jul 18, 2015 9:29 pm
by oLaudix

Code: Select all

if player.cursor_stack ~= nil then
	game.player.print(player.cursor_stack.name)
else
	return
end
As long as i have item in my "hand" it works. If I change item for an item it works fine as well. But when i put item in empty slot and my hand is empty it throws exception at "game.player.print(player.cursor_stack.name)". But from what i understand it shouldn't even get to that part of code if my hand is empty?

Re: player.cursor_stack ~= nil always true?

Posted: Sat Jul 18, 2015 9:38 pm
by Choumiko
0.12 changes:
Changed LuaEntity::stack, LuaEntity::held_stack and LuaPlayer::cursor_stack to return LuaItemStack objects.
Changed LuaItemStack to allow reading any inventory slot even when the item in the slot is invalid. LuaItemStack::valid_for_read should be used before accessing the normal properties/methods for a given LuaItemStack.
if player.cursor_stack.valid_for_read then ...
should be the new way to do it

Re: player.cursor_stack ~= nil always true?

Posted: Sat Jul 18, 2015 9:59 pm
by oLaudix
It works great now. Thank you.