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

How to get all the s?ame table index

Asked by 4 years ago
Edited 4 years ago
local Table = {Sao = 'S',Sao = 'U',Sao = 'C',Sao = 'K',Sao = 'S'}

for i,v in pairs(Table) do
    print(i)
end

--Only Prints Sao Once I want it to print 5 times

--[[  --]]

--What Im triyng to do



local Table = {Sao = 'S',Sao = 'U',Sao = 'C',Sao = 'K',Sao = 'S'}

local AmountOfSao = 0

for i,v in pairs(Table) do
    if i == 'Sao' then
        AmountOfSao = AmountOfSao + 1
    end
end


print(AmountOfSao) -- Should print 5


Basically I want to add all the index up and print a number how how many same indexes there are

AmountOfSao should print 5

0
Sao is all the same. Like I think all this does is change what Sao in the table so there is only one (I think). So like you need to have everything different. Phyrixia 51 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Table indexes are unique; you cannot have duplicate/same indexes in a table Use an array or change each index in your Table

Ad

Answer this question