So I have a table here
local TABLE = {
One = 1;
Two = 2;
Three = 3;
}
local RANDOM_ELEM = math.random(1, #TABLE)
print(RANDOM_ELEM)
Line 7 gives me the error.
So I have a table here
local TABLE = {
One = 1;
Two = 2;
Three = 3;
}
local RANDOM_ELEM = math.random(1, #TABLE)
print(RANDOM_ELEM)
Line 7 gives me the error.
local TABLE = {1, 2, 3}
local RANDOM_ELEM = math.random(1, #TABLE)
print(RANDOM_ELEM)
Removing the Keys for each of them should fix the problem
(normally index values would look like ["One"], although testing with that didn't seem to work)
That is a dictionary, not a table. You will need to write your own custom function to measure the length of a dictionary. I just made a simple one for you.
Code:
local TABLE = {
One = 1;
Two = 2;
Three = 3;
}
function MeasureLength(x)
local l = 0
for _,t in pairs(x) do
l = l+1
end
return l
end
local length = MeasureLength(TABLE)
local RANDOM_ELEM = math.random(1, length)
print(RANDOM_ELEM)
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
Thx! Also how many more questions do I ask? To get you to 2000?
Well if you calculated it would be (2000 - 1172) / 15 is approx. 56. Of course, I'll answer any question if I'm able to that hasn't already been answered, though its not guaranteed.
Huh, I saw you at 800 two days ago, I am falling behind:)
Oh it worked the button showed up. Enjoy some reputation!