SolarPortal wrote:why not use the GUI editor? and load the gui on screen.
--[[
A quick attempt at a inventory system.
table info.
items.name
items.texture
items.health
items.amount -- for stackable items such as apples 3
--]]
obj = 0;
-- Set up the inventory
items = {} -- table for the inventory
itemSlots = 10 -- item slots avialable for the inventory
-- itemSize = = newType.vec2(64,64); -- Used to set the size of the texture
function onInit(objID) -- You can preload a table with items if you wanted to
obj = objID;
--sky.print("Scene Script Acitve");
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 Inventory.Display () -- function used to display the inventory on screen
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
<img id="image1" src="myTexture.png" width="128" height="128">
or
<div id="name" style="position: absolute; top: 0; left 0; height:128px; width:128px;" class="myclass">
gui.setAttribute(guiID, elementName, attribute, value)
string = gui.getAttribute(guiID, elementName, attribute)
string = gui.getProperty(guiID, elementName, attribute)
<div id="image1Frame" style="display: inline-block; background: #ff0000; width: 128px; height: 128px;">
<img id="image1" src="cliff.jpg" width="128" height="128" />
</div>
-- | Here is how you change the size of a div tag using the gui.setProperty function. This is a style edit and not an attribute.
-- | You can use gui.setScaleYCent(), gui.setScaleXCent(), gui.setScaleY(), gui.setScaleX() direct for easier to read code, but this is the more raw way lol :P
gui.setProperty(guiID, "image1Frame", "height", "64")
gui.setProperty(guiID, "image1Frame", "width", "100")
-- | This is how you change the image texture:
gui.setAttribute(guiID, "image1", "src", "defaultRoadTextureOther.png") -- Notice the the setAttribute used instead.
-- | Change the size of the <img> to match the <div> by getting the <div> tags width and height properties.
height = gui.getProperty(guiID, "image1Frame", "height");
width = gui.getProperty(guiID, "image1Frame", "width");
gui.setAttribute(guiID, "image1", "width", width)
gui.setAttribute(guiID, "image1", "height", height)
Users browsing this forum: No registered users and 9 guests