Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control problems

I am having a problem with my control statement. I have just started programming.


math.randomseed(os.time())
answers = {
123,
132,
231,
213,
321,
312
}
outcomes = ( answers[ math.random( #answers ) ] )
print("What is your first guess?")
io.write("Guess#1: \n")
g1 = io.read()
onetwothree()
function onetwothree()
if o = 123 and g1 = 321 then
print("You have no numbers correct")
end
end

os.execute("PAUSE")

When I run the code in my IDE, it displays this:

>lua -e "io.stdout:setvbuf 'no'" "Mastermind.lua" 
lua: Mastermind.lua:25: 'then' expected near '='
>Exit code: 1

By the way, line 25, in my code is this:

if o = 123 and g1 = 321 then

How do I fix this and what is happening.

like image 895
Rohan K. Avatar asked Aug 07 '26 07:08

Rohan K.


1 Answers

The problem is you're using = for comparison instead of ==.

Change your condition to:

if o == 123 and g1 == 321 then
like image 196
guilespi Avatar answered Aug 08 '26 20:08

guilespi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!