Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to clear tables second value?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

So I have this table, and I want to change all the 0's to 1's, How would I go about this?

colors = {
    {"Gray",0},
    {"Cyan",0},
    {"Brown",0},
    {"Green",0},
    {"Pink",0},
    {"Peach",0},
    {"Blue",0},
    {"Purple",0},
    {"Red",0},
    {"Yellow",0},
}

1 answer

Log in to vote
0
Answered by
KoreanBBQ 301 Moderation Voter
8 years ago

You can iterate through a table with a for loop.

Since your table contains tables, you will want to do:

for i,inTable in pairs(colors) do
    inTable[2]=1
end
Ad

Answer this question