Skip to content

Instantly share code, notes, and snippets.

@bucketh3ad
Last active December 18, 2015 11:18
Show Gist options
  • Save bucketh3ad/5774569 to your computer and use it in GitHub Desktop.
Save bucketh3ad/5774569 to your computer and use it in GitHub Desktop.
Currently broken drop function
---
-- 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
@bucketh3ad
Copy link
Author

assert(itemNode.draw,... on line 14 always fails. I figured that since the node is saved in the item under props 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 attempted NodeClass.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment