mercredi 22 mars 2023

How can I make it so a global variable with "math.random()" will give me a new number every time? (Lua)

Every time I use a variable (eggs, spam, hams, and yams) and use a random function from the math library (math.random(100)) in Lua, it keeps giving the same exact number it randomized the first time. How can I edit the code so it will give a new randomized integer every time it is run?

spam = math.random(100)
eggs = math.random(100)
yams = math.random(100)
hams = math.random(100)

if eggs > spam then
  print("eggs are better than spam")
end

if spam > eggs then
  print("spam is better than eggs")
end

if yams > hams then
  print("yams are better than hams")
end

if hams > yams then
  print("hams are better than yams")
end

print(spam)
print(hams)
print(eggs)
print(yams)

I Tried using a goto function to a label, but Lua didn't recognize Label. Like this:

:: Label ::
--further code
goto Label



Aucun commentaire:

Enregistrer un commentaire