math.random(), a script that randomizes things.
math.random() that is blank, generates a number between 0 and 1. For an example:
math.random() Expected Output: -- the console is the output.
0.986203 -- this is our answer. Listen closely. this next part is going to be a little harder to understand. So read multiple times to understand!
a math.random() with numbers in it such as math.random(1,8) generates a number between 1 and 8
math.random(1,8)
print(number) Expected Output:
3
Let's try making a script out of this.
local numbers = math.random(1,3) -- a local must always be behind the value you want to. Unlike Python, you can just use numbers = instead.
if numbers == 1 then -- must be double equals or it will break. In Python, then dosen't exist. You instead use : instead of then.
print("Value is 1.") -- prints it to the Output.
else if number == 2 then -- I strongly prefer else if instead of elseif. The elseif dosen't generate an end. It just is a definition that if something else happens, it does that.
print("Value is 2.")
else if numbers == 3 then
print("Value is 3.")
end
end
end -- an end must ALWAYS be after if an function like if then, while do, function() and more. The script will BREAK if you don't put an end in it.
0 comments