Posted 02 March 2012 - 08:18 PM
I was wondering if there was a way to randomly pick one thing from a bucket of others? So, like random("red, blue, green, purple") and it'd pick one out of that, as an example.
local items = {"apple", "pie", "banana", "orange"}
print(items[math.random(1, #items)]) -- Pick a random item
-- Do it again a few times:
for i = 1, 10 do
print(items[math.random(1, #items)])
end
local items = {"apple", "pie", 4 = "banana"}
print(#items) -- This will print 2, since items[3] is nil.
Is there a way to do it with words?math.random(min, max)
local items = {"apple", "pie", "banana", "orange"}
print(items[math.random(1, #items)]) -- Pick a random item
F i derped sorryYou can't have a variable called 8.