How to set limit to a table ?
Posted: Tue Oct 10, 2017 4:09 pm
Hi guys !
I've 2 problems, I want to create a system inventory, so I have created an image which contains 48 places for items, and I want to say "If you have more than 48 items, you can't take this one !". Si I tried many things ...
Here's my code :
But the player can get more than 48 items ... I also tried 47 and 49 but it didn't change anything.
Y second problem is that the player doesn't get only 1 item but a random number with this code :
But the player doesn't take only 1 item, but a random number (I don't know why) ...
I tried to replace the table.insert by :
I also tried few things but I don't remember what, and nothing worked ...
I've 2 problems, I want to create a system inventory, so I have created an image which contains 48 places for items, and I want to say "If you have more than 48 items, you can't take this one !". Si I tried many things ...
Here's my code :
Code: Select all
if hero.inventory[48] ~= nil then
canGetItem = false
else
canGetItem = true
end
Y second problem is that the player doesn't get only 1 item but a random number with this code :
Code: Select all
if collisionPlayer(hero, musicSheet) == true then
musicSheet.isVisible = false
if canGetItem == true then
table.insert(hero.inventory, musicSheet)
end
end
I tried to replace the table.insert by :
Code: Select all
hero.inventory[hero.inventory.i] = musicSheet
hero.inventory.i = hero.inventory.i+1