How would i do this?

hI dEVs,

i have seen this

local randomBool 

if math.random(1, 2)== 1 then
 randomBool = true
 else
 randomBool = false
end

which is the same thing as

local randomBool = math.random(1, 2) == 1 and true or false

but is there a way to do this?

if math.random(1, 3)== 1 then
 randomBool = "y"
 elseif math.random(1, 3)== 2 then
 randomBool = "ya"
 else
 randomBool = "yay"
end

how would i do this?

Isn’t the 3rd thing just

local randomBool = math.random(1,3)
1 Like

i know it was just an example my real question is drum role please how would i use elseifs in a variable if you can even use it

You cannot, you can only really use and or or, elseifs are for if statements, you could do your if-elseif statement via chaining

local rand = math.random(1,3)

local bool = (rand == 1 and 1) or (rand == 2 and 2)  or (rand == 3 and 3)

print(bool)

Wow I’m late to the party

1 Like

what do you mean by that???

Someone had already posted almost exactly what I had posted myself, except they used the Random class instead of math.random

1 Like