Help with Inventory system!

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Rondu
Prole
Posts: 7
Joined: Mon May 27, 2024 2:52 am

Help with Inventory system!

Post 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!
Attachments
InventoryWork_9.love
(59.31 KiB) Downloaded 166 times
User avatar
marclurr
Party member
Posts: 146
Joined: Fri Apr 22, 2022 9:25 am

Re: Help with Inventory system!

Post by marclurr »

Can you explain how you want the delete interaction to work, and what you have tried so far?
User avatar
Rondu
Prole
Posts: 7
Joined: Mon May 27, 2024 2:52 am

Re: Help with Inventory system!

Post 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!
Last edited by Rondu on Mon May 27, 2024 7:05 pm, edited 1 time in total.
User avatar
Rondu
Prole
Posts: 7
Joined: Mon May 27, 2024 2:52 am

Re: Help with Inventory system!

Post 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
User avatar
Rondu
Prole
Posts: 7
Joined: Mon May 27, 2024 2:52 am

Re: Help with Inventory system!

Post 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
Attachments
InventoryWork_9.love
(66.81 KiB) Downloaded 127 times
User avatar
H.I
Prole
Posts: 8
Joined: Wed Mar 29, 2023 3:34 pm

Re: Help with Inventory system!

Post 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.
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Help with Inventory system!

Post 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
User avatar
Rondu
Prole
Posts: 7
Joined: Mon May 27, 2024 2:52 am

Re: Help with Inventory system!

Post by Rondu »

Ok..thank you!!! I will go through it as soon as I can! If you need any art please let me know!
RNavega
Party member
Posts: 355
Joined: Sun Aug 16, 2020 1:28 pm

Re: Help with Inventory system!

Post 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"
User avatar
Rondu
Prole
Posts: 7
Joined: Mon May 27, 2024 2:52 am

Re: Help with Inventory system!

Post 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!
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests