How to remove table from dictionary

hopefully im being specific, i need help removing a table from a dictionary. here is an example

local storeitems = {
{
Food = "Apple",
Rotten = false
},

{
Food = "Bannana"
Rotten = false
},
}

table.remove(storeitems, storeitems[math.random(1,#storeitems)]

Error

invalid argument #2 to 'remove' (number expected, got table) 

I forgot that table.remove is only for certain indexes but im trying to removing the whole table. Any idea how?

What you can do is this:

local chosenNumber:number = math.random(1,#storeItems);

storeItems[chosenNumber] = nil;
1 Like

How about storing/trasnferring the table in another dictionary?
for say
local storage = {}

In that case, you’d first need to clone the table.

local chosenNumber:number = math.random(1,#storeItems);
local tempTable = {};

for i,v in storeItems[chosenNumber] do
    tempTable[i] = v;
end;

storeItems[chosenNumber] = nil;

storage[#storage + 1] = tempTable;

quick question, what is chosenNumber:number mean, like the :

It’s used to assign it a type. The interpreter will interpret that this variable will always be a “number” type. It is in no ways needed at all, I am just used to it.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.