I did some reading up on why you can't print(Types[1]). Or print(#Types) keeps returning 0. Here's a quote from:
lua.users.org
The # operator doesn't count all the items in the table (!). Instead it finds the last integer (non-fractional number) key. Because of how it's implemented its results are undefined if all the integer keys in the table aren't consecutive. Which is why it shouldn't be used for tables used as sparse arrays[2]).
If you go to the website and click the "2" it will lead you to Wikipedia and you can read more about it.
Interval is empty because you tried to do math.random(1,0)
Not sure if this is the best approach but you can explicitly assign an Index value in your tables.
local Types = {
["LeftPunch"] = {Index = 1, Id = 1784490345, DamagePart = "LeftHand", Damage = 10},
["RightPunch"] = {Index = 2, Id = 1784483797, DamagePart = "RightHand", Damage = 10}
}
local numOfPunches = 0
print("What is #table: " .. #table)
print(#Types)
print(Types[1])
for punchType,entry in pairs(Types) do
numOfPunches = numOfPunches + 1
print(punchType .. " " .. tostring(entry))
end
print("You have " .. numOfPunches .. " types of punches.\n")
local function RandomPunch()
local rng = math.random(1,numOfPunches)
for _,entry in pairs(Types) do
if entry.Index == rng then
print(entry.DamagePart .. " did " .. entry.Damage .. " damage.")
end
end
end
while wait(1) do
RandomPunch()
end
3 comments
#Types instead of #table?
nope
You don't have a table named "table" and you can't anyways.