Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

lua script for inventory

Recommended Posts

Make a table and write your items in it like this:


This will add 3 swords into your inventory. Then in PostRender you check if inventory menu is opened, and if it is you loop through inventory and draw items icons:

for i=1, #self.inventory do
context:DrawImage(Texture:Load("folderWithIcons/"..self.inventory[i].name), 100, 100+i*50)
context:DrawText(self.inventory[i].amount, 120, 100+i*50)

Link to post

hi there thanx for the script but i have tried to sort mine out lol


i have restarted it all again when im on the final bit putting the item into my inventory nothing happens.


i have looked in the output and it says "we got the inventory Item B we place the bottle in the inventory


Loading shader "E:/leadwerks/MyGame/Shaders/Model/default.shader.....

process complete."

Link to post

i just added the self.items before the return and still the same lol i also downloaded the script and used that so i know they wouldn't be any typo but for some reason its not drawing my bottle icon ? im finding it hard as im not used to Lua or c++ in the past i used a built in interface GML i think it was called it was set out different to what im used to so finding errors is abit difficult for me lol sorry to be a big pain for you guys lol

Link to post

Replace the PostRender function with the script below.


Tell us what the output is and whether your see something on screen.

function Script:PostRender(context)

for i = 1, self.itemSlots, 1 do


local x = self.screenWidth - self.itemSize.x

local y = (i * self.itemSize.y) + (i * self.offset)

context:DrawRect(x,y, self.itemSize.x, self.itemSize.y)

local currentItem = self.items

if currentItem ~= nil and currentItem.texture ~= nil then

System:Print("going to draw a texture. i="..i..)


context:DrawImage(currentItem.texture, 0, 40 * i, 40, 40)





Link to post

Can you post an ingame screenshot?


It looks like the textures are missing, but I wonder why it isn't causing errors. Can you do a quick test by putting this line right after the PostRender function (assuming the location of the texture is correct):

context:DrawImage(Texture:Load("Materials/items/bottleicon.tex", 0,0, 100, 100)

Link to post

yes i have a picture drawn haha what do i do now ? its in the top left it already draws it when you start the game


i also was putting ")"


when you said but it was saying error soio kept starting the game and it finally came on so i there a glitch in the system ?


Link to post

It was a simple test to check if the texture location was correct, and yes is was supposed to be drawn there.

Lets try out severall drawImage commands. Replace the if statement with the following:

if currentItem ~= nil and currentItem.texture ~= nil then
context:DrawImage(Texture:Load("Materials/items/bottleicon.tex"), x, y, self.itemSize.x, self.itemSize.y)
context:DrawImage(currentItem.texture, 0, 0, self.itemSize.x, self.itemSize.y)
context:DrawImage(currentItem.texture, x, y, 80, 80)

Link to post
  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Facebook Twitter Youtube Github Steam
  • Create New...