Search the Community
Showing results for tags 'Jorn'.
-
Removing items from Inventory after Use (Project Saturn scripts)
intog posted a topic in Programming
Hi everyone, I'm new here and somewhat new to programming (other than Actionscript 8 years ago and OpenSCAD modeling recently) I followed through Jorn's Project Saturn videos and now I'm wondering how I can finish the inventory scripts on my own. Jorn left off with an open function for using the item, but didn't go into how to remove the item after it's used. I'm guessing I need to remove that item's table from the inventory table but am a little lost on doing that and also since there are 3 scripts working together for the inventory, I'm not sure where this function would reside. Here is my bottle.lua script that I modified slightly to make it reusable for other items: Edit: Nevermind I fixed it on my own by adding a new variable to the table using the code in red: --this was the Bottle.lua script-- Script.InvIcon = "" -- path "Icon" "Tex file (*tex) :tex" Script.collectOnce = true -- bool "Collect once?" Script.reuseItem = true -- bool "Reuse Item?" Script.itemName = "Item" --string "Item Name" Script.useOnce = true -- bool "Use Once?" function Script:Use(player) -- allows hand use local playerInventory = player.script:GetInventory() -- reference player inventory if playerInventory == nil then error("no inventory") end System:Print("we got inventory") if not playerInventory:IsFull() then -- if inventory is NOT full, then: System:Print("we place the " ..self.itemName.. " into the inventory") local item = self:CreateInventoryItem() playerInventory:AddItemToInventory(item) if self.collectOnce then self.entity:Release() end end end function Script:CreateInventoryItem() item = InventoryItem:Create() item.name = self.itemName item.texture = Texture:Load(self.InvIcon) item.useOnce = self.useOnce item.UseInventoryItem = function() System:Print("You used the " .. self.itemName .. "!") end return item end Then I updated the use function in Inventory.lua (from the videos): if self.items.useOnce then self.items = nil end Thanks for your help!