Page 1 of 2
Help with Inventory system!
Posted: Mon May 27, 2024 5:49 am
by Rondu
I have a inventory(card) system im trying to implement
im using a code "snip-it" to start with and have been slowly learning the insides of what makes
it work... and im having a problem deleting the cards! I would be thankful for any help!
If you need art for your game please let me know!
Thanks!
Re: Help with Inventory system!
Posted: Mon May 27, 2024 2:31 pm
by marclurr
Can you explain how you want the delete interaction to work, and what you have tried so far?
Re: Help with Inventory system!
Posted: Mon May 27, 2024 3:53 pm
by Rondu
When you click on item it goes into yr mouse pos...like it's in yr hand..I want to be able to delete the card in the table
when its in my hand....or thow it at the door to use!!! script (inventoryGui.lua) approximate line 194 I have a comment explaining!
Please if you can help in any way! Thank You! I do insane art if you need anything!
The table item is there..I just cant seem to access it and delete that card thats in my hand..but keep any cards already in inventory!
Basicly a card gets put into inventory..you can move it around yr inventory....throw it at trash rectangle collision box below...or throw it at door rectangle collision box....You basicly get cards and throw them at the playfield to fix the door and stuff..or throw them in trash!
Re: Help with Inventory system!
Posted: Mon May 27, 2024 6:36 pm
by Rondu
This is the another version..I added a desrciption of what im trying to do along with instructions on line 194 in inventory.Gui.lua
Re: Help with Inventory system!
Posted: Mon May 27, 2024 6:39 pm
by Rondu
This is the another version..I added a desrciption of what im trying to do along with instructions on line 194 in inventory.Gui.lua
Re: Help with Inventory system!
Posted: Sat Jun 08, 2024 8:15 am
by H.I
if i understand your request, you need to
put this code in inventory.lua
Code: Select all
-- ix = index x, iy = index y in table
function inventory:removeItem(iy,ix)
local stop = false
for y=1,#self.arr do
for x=1,#self.arr[1] do
self.arr[iy][ix] = 0
break
end
end
end
any time you want to delete an item from table(inv) just call
inv:removeItem(row,coulmn) put the exact row and column of the item, then the item will be deleted.
Re: Help with Inventory system!
Posted: Sat Jun 08, 2024 10:01 am
by dusoft
table.remove is better suited as it does not leave hanging elements around, 0 does not equal nil etc.
https://www.lua.org/pil/19.2.html
Re: Help with Inventory system!
Posted: Sat Jun 08, 2024 11:11 am
by Rondu
Ok..thank you!!! I will go through it as soon as I can! If you need any art please let me know!
Re: Help with Inventory system!
Posted: Mon Jun 10, 2024 12:43 am
by RNavega
H.I wrote: ↑Sat Jun 08, 2024 8:15 am
Code: Select all
-- ix = index x, iy = index y in table
function inventory:removeItem(iy,ix)
local stop = false
for y=1,#self.arr do
for x=1,#self.arr[1] do
self.arr[iy][ix] = 0
break
end
end
end
Hi. In that code the loops are redundant as you're not using the "x" and "y" variables.
The function can be reduced to just this line, "self.arr[iy][ix] = 0"
Re: Help with Inventory system!
Posted: Mon Jun 10, 2024 1:37 am
by Rondu
Thank you for the valuable info! I will go through this as soon as I can and post my work! If anyone needs art please let me know!