I have a math.random code that gives you a random number:
local theRanNum = math.random(1,5)
if theRanNum == 1 then
print("You got 1!!")
end
if theRanNum == 2 then
print("You got 2!!")
end
if theRanNum == 3 then
print("You got 3!!!")
end
if theRanNum == 4 then
print("You got 4!!!!")
end
if theRanNum == 5 then
print("You got 5!!!!!")
end
Is there anyway I can make this shorter so I don’t have to type out every single number?
If you wanted to do more than print, and maybe something for each number you could involve an array of functions and then you could pull the function out of the array and all it.
I’d also recommend that you use the Random datatype, it has it’s own seed per object and has mutliple functions.
For example:
local FunctionsArray = {
function()
print("You got 1!")
end,
function()
print("You got 2!")
end
}
local Rand = Random.new()
local RandomNumber = Rand:NextInteger(1, 2)
local RandomFunction = FunctionsArray[RandomNumber]
RandomFunction()