--[[ A quick attempt at a inventory system using the GUI SYSTEM. Currently stuck on getting the GUI table cells updated with a texture from lua. table info. items.name items.texture items.health items.amount -- for stackable items such as apples 3 --]] --Declaration x=27;y=4; obj = 0; win1 = 0; guiID = "inventory"; items = {} -- table for the inventory itemSlots = 10 -- item slots avialable for the inventory function onInit(objID) sky.lprint("LUA: Inventory GUI Scripts active!"); obj = objID; gui.workSpace("inventory/"); -- Standard gui stuff win1 = gui.load("inventory.rml",0,20); gui.hide("win1","win1"); setPosition(inventory, win1, x, y ); -- set the position of the Inventury GUI on the Screen inventury.Populate() -- temporary to populate table end -- populate a test table for the inventory complete with items, called from onInit for tidyness function inventury.Populate() sky.lprint("LUA: populating table"); items[0] = item1 items[1] = item2 items[2] = item3 end function onKeyDown( key ) -- If the "i" key is pressed the open the inventory if(key == "i") then gui.show("win1","win1"); -- Show the Inventory GUI. -- The GUI pulls inventury items and textures end end function inventory.Display() end function Inventory:Add (item) -- Add items to the Inventory for i = 1, itemsSlots, 1 do -- Look for an empty slot if items [i] == nil then -- If the slot is nil then inset the item into that items [i] = item -- slot return -- ends the for loop and returns from the function end -- ** you could check if stack it at its max like 3 apples end -- if your inventory can only hold 3 apples in a slot end function Inventory:Delete(itemName) -- Delete Item from inventory for i = 1 itemSlots, 1 do -- can call this if an item is used and no longer if items.mane == itemName then -- available item [i] = nil -- makes the slot nil so can be populated again return -- ends the for loop and returns from the function end end end function inHand() -- function for items placed from the inventory into a -- usable slot (taken from a bag into a pocket to be used -- for instance. end