I'm having trouble with creating a random number.

Hi.

I’m new to this Lua thing, and i’m having some trouble.

I’ve programmed before (in Java), so usually i know what i am doing.

This piece of code is somehow not working. I have no idea why.

It’s a Tic tac toe AI, that should choose a random place to make it’s turn.

The first if-statement works, but after “playersTurn = true; computersTurn = false” nothing happens.

Please help.

 if computersTurn == true and row1[1] == 0 and row1[2] == 0 and row1[3] == 0 and row2[1] == 0 and row2[2] == 1 and row2[3] == 0 and row3[1] == 0 and row3[2] == 0 and row3[3] == 0 then playersTurn = true; computersTurn = false randomPlacement = math.random(1, 8) if randomplacement == 1 then row1[1] = 2 end if randomplacement == 2 then row1[2] = 2 end if randomplacement == 3 then row1[3] = 2 end if randomplacement == 4 then row2[1] = 2 end if randomplacement == 5 then row2[3] = 2 end if randomplacement == 6 then row3[1] = 2 end if randomplacement == 7 then row3[2] = 2 end if randomplacement == 8 then row3[3] = 2 end end

If this is the entirety of your code, it would appear that you are setting the computersTurn to false, which would not allow this particular function to be called the next time it runs, as it is waiting for a computersTurn value of true to exist. If you take this portion out, it should run again.

upper/lowercase issue?  you have randomPlacement (cap-P) and randomplacement (lower-p)

Thanks, it worked… I feel stupid now, haha

If this is the entirety of your code, it would appear that you are setting the computersTurn to false, which would not allow this particular function to be called the next time it runs, as it is waiting for a computersTurn value of true to exist. If you take this portion out, it should run again.

upper/lowercase issue?  you have randomPlacement (cap-P) and randomplacement (lower-p)

Thanks, it worked… I feel stupid now, haha