I am currently learning LUA and trying to make a script for a game. So far everything works fine, but i stuck at a problem and i cant figure out how to do this.
For example i have a LUA file with this content:
DATA["1234"] = {"Admin", 0, 0}
DATA["2793"] = {"Supporter", 0, 0}
DATA["1599"] = {"VIP", 0, 0}
DATA["6473"] = {"User", 0, 0}
- DATA = Tablename
- ["1234"] = Player IDs
- {"",0,0} = 3 Values for each DATA
What i want is something that give me the number of DATAs i have. In this example i have 4 DATAs. When a new Player comes i have 5 DATAs but how can i get the number of "Keys" or "DATAs" i have?
I need this for a Player-Save function.
EDIT:
I forgot something important, sorry..
I need the Keynames as well, its very important!
This works fine:
function tableLength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
But how can i get the keynames of all DATAs?
Btw: The playerId is the SteamID
Something like:
for k, v in pairs(DATA[playerId]) do
--Code here
end
-- Results:
1234
2793
1599
6473