Jump to content

Recommended Posts

Posted

can someone please help me i made a inventory for my game but when you place items in the inventory the image does not show i have gone over and over cant cant find the error.

 

can anyone do me a working inventory script please :-) would appreciate it.

  • Upvote 1
Posted

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

self.inventory[#self.inventory+1]={}
self.inventory[#self.inventory].name="Sword"
self.inventory[#self.inventory].amount=3

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)
end

Posted

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

bottle

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

process complete."

Posted

In function AddItemToInventory you forgot self.items=item before the return.

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Posted

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

Posted

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

context:SetColor(1,1,1)

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:SetBlendMode(Blend.Alpha)

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

context:SetBlendMode(Blend.Solid)

end

end

end

Posted

in the system:print i have a error where you have ..1..) unexpected symbol as in the picture i sent and then in second picture i removed the symbol and got this reading from the output shown in the picture below

post-13477-0-95921500-1426251534_thumb.png

post-13477-0-71508300-1426251549_thumb.png

Posted

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)

Posted

iput theline of code in but not sureif i have it in the right place this error came up in the first picture

 

in the second picture i removed thatcode and done a in gameplay screen shot

post-13477-0-30522100-1426256762_thumb.png

post-13477-0-69707400-1426256784_thumb.png

Posted

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 ?

post-13477-0-49990500-1426263512_thumb.png

Posted

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:SetBlendMode(Blend.Alpha)
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)
context:SetBlendMode(Blend.Solid)
end

Posted

hi i was making a turret and made a new pivot for my player chest and the line of code you gave me for the draw image for my inventory have came up like this in the picture.

 

i was wondering if my inventory wasn't a parent ?

post-13477-0-69505400-1426361835_thumb.png

  • 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.
Note: Your post will require moderator approval before it will be visible.

Guest
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.

×
×
  • Create New...