Editing a table within a table without using indices

Hello,
Let’s say you have a table like the one below and you want to edit a table of choice without making reference to any index.

Is there something like table.insert or something that could do this?

local Table1 = {
	{90, "A"};
	{2, "B"};
	{3, "C"};
	{20, "D"};
	{5, "E"}
}

What do you mean by “a table of choice” if you don’t know which table you want? How do you expect to be able to determine which table is the one you want?

2 Likes

Good question.

Let’s say I want to edit The first table without making any reference to Index 1 how would I be able to do it?

If it’s the first table, and the only information you have is that it’s the first, then the index is 1, isn’t it? What information do you have to identify the table?

2 Likes

Sorry if it’s not clear enough btw, the situation in my game is kind of different so I tried to make a simpler example of it here, but I will explain what I am trying to currently do.

I am making a game about collecting cards and I am putting the duplicate cards (Each card has an individual table with details) in a table where they are sorted by a number. If you find that card again I want to increase a value in the Player’s table by 1.

So about information, I would only know the values in the Player’s table. That’s why I can’t use indices as I wouldn’t know on what index of ‘Table1’ the player’s table is.

Couldn’t you just use a for loop to search through the values of the table by doing something like this:

 function Find(value, Table)
   for  _,v in pairs(Table) do
  if v[1]  == value then
   return v , _
    end
 end
end

Or if you didn’t know the index of the value and you didn’t need it specified in any given table you could replace this: ( if you were simply searching any table to check if the value given was inside of it)

if v[1]  == value then

With table.find

if table.find(v, value) then
2 Likes

Good idea.

I will try this out thank you!