How to remove an item that is picked up?

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.
Post Reply
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

How to remove an item that is picked up?

Post by hasen »

I have items that are stored in a file within a simple table with their name/type and their position in the room stored. What would be the best way to remove them from the map so if the player returns to the same room later the item is permanently gone? Using

Code: Select all

table.remove
doesn't work that well because it doesn't remove the specific item that was picked up, it just removes one element from the array.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to remove an item that is picked up?

Post by zorg »

So if you have something like this in a file:

Code: Select all

return {
{'ball','toy',1,1},
{'chair','furniture',2,1},
{'desk','furniture',3,1},
}
and you load it into a table called items, let's say, then your code already checks against the position of the items, which means you also know the index of one item in said table; then you can just do table.remove(items, index) where items is the name of the table you assigned the returned table to, and index is, well, the index of the item you want removed.

That said, if you always re-load the contents from disk each time your player enters the room, you also need to save out the edited table back to the file.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: How to remove an item that is picked up?

Post by hasen »

I actually solved this almost right after I posted it but thought I'd see what people say anyway. What I did was added a key element when the pickup item objects are created. Then when the item is picked up the key is passed through the object when it gets removed and hence the table.remove can remove the correct one from the table.
jackmartin
Prole
Posts: 3
Joined: Tue Jun 12, 2018 5:44 am
Location: MD,USA
Contact:

Re: How to remove an item that is picked up?

Post by jackmartin »

Try waiting a tick before removing it.When the player picks up an item in an item that is a picked up.
User avatar
Stifu
Party member
Posts: 106
Joined: Mon Mar 14, 2016 9:53 am
Contact:

Re: How to remove an item that is picked up?

Post by Stifu »

Don't wanna play forum police here, but he said he solved his problem already... several months ago.

Edit: hmm... looking at his other posts, that guy kinda looks like a bot.
Zabuyaki, our upcoming beat 'em up: https://www.zabuyaki.com
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to remove an item that is picked up?

Post by zorg »

Stifu wrote: Tue Jun 12, 2018 5:38 pm Don't wanna play forum police here, but he said he solved his problem already... several months ago.

Edit: hmm... looking at his other posts, that guy kinda looks like a bot.
Or just someone who uses google to search löve's forums for threads, tries to be a good samaritan, and doesn't know english well.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: How to remove an item that is picked up?

Post by Nixola »

Nope, was a bot. Its signature was some indian website coding thing and it has a few (six) unapproved posts because most just don't make sense.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: No registered users and 40 guests