Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua string comparison not working

Well I am learning Lua at the moment and I wanted to write a little script. It's just for practice and understanding how Lua is working.

   local name = io.read()

 if name == Test
  then print("Right")
  else print("Wrong")
end

Normally the output should be "Right" if I enter "Test" but it always prints "Wrong". I tried it many times and wrote the code in other forms but didn't get my solution.

Can anyone help me please?

like image 434
innuendomaximus Avatar asked Dec 28 '25 17:12

innuendomaximus


1 Answers

You're missing a set of quotation marks.

This:

if name == Test

compares the values of two variables, name and Test.

You want this:

if name == "Test"

Lua doesn't require variables to be declared, so this is an easy mistake to make.

like image 112
Keith Thompson Avatar answered Dec 31 '25 19:12

Keith Thompson