If math.random = certain number do something

Hey guys I cant seem to figure out how to make it so when the math.random = a certain number then do what is inside the if statement.

local function timer1( event ) tmr = tmr - 1 timerdis.text = (tmr) print(tmr) if tmr == 0 then print("life is over") timerdis:removeSelf() print(options[math.random(1, 5)]) local outcome = display.newText(options[math.random(1, 5)],150,350,nil,32) if outcome == 1 then print("You got 20 points!") end if outcome == 2 then print("You got 100 points!") end if outcome == 3 then print("You got 50 points!") end if outcome == 4 then print("You got 0 points!") end if outcome == 5 then print("You got 30 points!") end end end

The problem is that outcome is a display.newText() object.  It’s a table of values binary data that draws text the screen.  You are trying to compare a table to a number.  Perhaps you should do something like this:

    local option = math.random( 1, 5 )     print( options[option] )     local outcome = display.newText( options[option], 150, 350, nil, 32 )     if option == 1 then      ...

Thanks it worked like a charm! :slight_smile:

The problem is that outcome is a display.newText() object.  It’s a table of values binary data that draws text the screen.  You are trying to compare a table to a number.  Perhaps you should do something like this:

    local option = math.random( 1, 5 )     print( options[option] )     local outcome = display.newText( options[option], 150, 350, nil, 32 )     if option == 1 then      ...

Thanks it worked like a charm! :slight_smile: