Last active
December 18, 2015 11:18
-
-
Save bucketh3ad/5774569 to your computer and use it in GitHub Desktop.
Currently broken drop function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
-- Drops the currently selected item and destroys it TODO: Prompt for confirmation and/or create a node. | |
-- @return nil | |
function Inventory:drop() | |
if self.craftingState == 'open' then return end --Ignore dropping in the crafting annex | |
local slotIndex = self:slotIndex(self.cursorPos) | |
if self.pages[self.currentPageName][slotIndex] then | |
local level = GS.currentState() | |
local itemNode = self.pages[self.currentPageName][slotIndex].props | |
local NodeClass = require('/nodes/' .. itemNode.type) | |
itemNode.x = self.player.position.x | |
itemNode.y = self.player.position.y | |
level:addNode(itemNode) | |
assert(itemNode.draw, 'ERROR: ' .. itemNode.name .. ' does not have a draw function! Type: ' .. itemNode.type) | |
assert(level:hasNode(itemNode), 'ERROR: Drop function did not properly add ' .. itemNode.name .. ' to the level!')--]] | |
self:removeItem(slotIndex, self.currentPageName) | |
sound.playSfx('pot_break') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
assert(itemNode.draw,...
on line 14 always fails. I figured that since the node is saved in the item underprops
when it is added to the inventory, it would be as simple as accessing that node data and adding it to the level. I've also attemptedNodeClass.new(itemNode)
but that goes down a whole rabbit hole of expected data and errors when those fields are nil.Bit stumped here. Any advice on how to proceed would be welcome.