This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Strite's profile picture

Mutiple Input Error

Started by Strite, 27 March 2014 - 11:31 PM
Strite #1
Posted 28 March 2014 - 12:31 AM
Hello World! What's up?
Anyway, I'm here because of a problem, that is probably extremely dumb, but it has been bothering me for a couple of minutes now.
Here's the code's pastebin link: http://pastebin.com/uTUqZ0XH
Starting at line 79, there is an input entry, but for some reason, the program understands every single entry as "Redstone", so, for some reason, even if I type "exit", the code starts the "redstone()" function.
I stopped playing with CC a couple weeks ago, only to get back to it now, so I'm a bit rusty.
Thanks for your attention and sorry for the noobish question! :x
CometWolf #2
Posted 28 March 2014 - 12:36 AM

  if com == "Redstone" or "redstone" or "rs" then
You're using the or statement incorrectly. Each one is idependent of the other, and in Lua a statement with just a variable is the equivalent of

if variable ~= nil then
And since the string "redstone" is obviously not the same as nil, it's considered true.

The correct syntax would be

  if com == "Redstone"
  or com == "redstone"
  or com == "rs" then
The extra lines is just a personal preference, and not nessacary. Also you might want to consider using string.lower() to convert the input to lowercase

local com = string.lower(read())
Strite #3
Posted 28 March 2014 - 12:39 AM
Thanks, CometWolf! That solved the problem.
And thanks for the tip, I'm sure it's going to be really useful.