Jump to content




if input ~= multiple inputs help


  • You cannot reply to this topic
12 replies to this topic

#1 SNWLeader

  • Members
  • 71 posts
  • LocationTampa Bay, Florida

Posted 20 September 2012 - 11:07 PM

I have this great Text Guide System Comming along for my practices with ComputerCraft.
I need to know how to get this to work with multiple words for input.

if input ~= "Command 1" or "Command 2" or "Command 3" then


Something like that how do i correctly put that in?

I might post my code when I am finished.
:)/>

#2 Mr. Fang

  • Members
  • 82 posts

Posted 20 September 2012 - 11:21 PM

Basically, you want the same sequence of events to happen to several different inputs...
Lemme know when you get an answer, I wanna know to....

#3 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 20 September 2012 - 11:30 PM

It's simple. You have the basic structure right, just the syntax a little muddled.
if input ~= "command 1" or input ~= "command 2" or input ~= "command 3" then
--you need to use the equations each time.
--if you are wanting it to be neither of these, switch the "or" to "and"


#4 Mr. Fang

  • Members
  • 82 posts

Posted 20 September 2012 - 11:48 PM

Do we need the "~=" or the ==?

#5 Fatal_Exception

  • New Members
  • 105 posts

Posted 20 September 2012 - 11:55 PM

Depends whether you want your condition to succeed when the values are true (==) or false(~=)

#6 Mr. Fang

  • Members
  • 82 posts

Posted 20 September 2012 - 11:55 PM

Thanx I have no clue when it comes to these things.

#7 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 20 September 2012 - 11:59 PM

The operator is defined like this:
~= does not equate to
== equates to

Pretty simple, one just means if it the result is anything EXCEPT this, and the other is if the result is EXACTLY this.

#8 GopherAtl

  • Members
  • 888 posts

Posted 21 September 2012 - 01:07 AM

actually you want "and"s in there, not "or"s. it'l'l always be not-equal to one of the three, so that version will run always.

#9 SNWLeader

  • Members
  • 71 posts
  • LocationTampa Bay, Florida

Posted 21 September 2012 - 01:10 AM

I keep getting the bios:206: [string "fprompt"]:14: unexpected symbol... here is the code I have made so far.
term.clear()
term.setCursorPos(1,1)
print("COM API 1.0")
print("Available Commands")
print("Current List Unavailable")
write("Command:  ")
input = read()
if input == "filter" then
shell.run "Filter_Prompt"
end
if input ~= "filter" or if input ~= "lights" or if input ~= "cancel" then
term.clear()
term.setCursorPos(1,1)
print ("Command Not Available")
end


#10 SNWLeader

  • Members
  • 71 posts
  • LocationTampa Bay, Florida

Posted 21 September 2012 - 01:12 AM

View PostGopherAtl, on 21 September 2012 - 01:07 AM, said:

actually you want "and"s in there, not "or"s. it'l'l always be not-equal to one of the three, so that version will run always.
read my post above. I used the quote to message you.

#11 Fatal_Exception

  • New Members
  • 105 posts

Posted 21 September 2012 - 05:01 AM

The error is caused by the 'if's in the line.
It should read:
if input ~= "filter" or input ~= "lights" or input ~= "cancel" then

But, as GopherAtl said, it's always going to be not equal to at least one of those conditions, making the end result true.

Or is true if ANY of the conditions are true.
And is true if ALL of the conditions are true.

In your case, it's better to just do
term.clear()
term.setCursorPos(1,1)
print("COM API 1.0")
print("Available Commands")
print("Current List Unavailable")
write("Command:  ")
input = read()
if input == "filter" then
  shell.run "Filter_Prompt"
elseif input == "lights"
  -- handle lights here
elseif input == "cancel" then
  -- handle cancel here
else -- anything we're not expecting
  term.clear()
  term.setCursorPos(1,1)
  print ("Command Not Available")
end


#12 SNWLeader

  • Members
  • 71 posts
  • LocationTampa Bay, Florida

Posted 22 September 2012 - 04:18 PM

Good all of my issues have been sorted out. I am getting the little system kinks worked and touchups.
thank you for all the help. :P/>

#13 android4682

  • Members
  • 15 posts
  • LocationThe Netherlands

Posted 02 February 2013 - 07:52 AM

Yes this is just the information I needed. Thanks so much! :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users