71 posts
Location
Tampa Bay, Florida
Posted 21 September 2012 - 12:07 AM
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.
:)/>/>
79 posts
Posted 21 September 2012 - 12:21 AM
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….
3790 posts
Location
Lincoln, Nebraska
Posted 21 September 2012 - 12:30 AM
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"
79 posts
Posted 21 September 2012 - 12:48 AM
Do we need the "~=" or the ==?
105 posts
Posted 21 September 2012 - 12:55 AM
Depends whether you want your condition to succeed when the values are true (==) or false(~=)
79 posts
Posted 21 September 2012 - 12:55 AM
Thanx I have no clue when it comes to these things.
3790 posts
Location
Lincoln, Nebraska
Posted 21 September 2012 - 12:59 AM
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.
871 posts
Posted 21 September 2012 - 02: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.
71 posts
Location
Tampa Bay, Florida
Posted 21 September 2012 - 02: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
71 posts
Location
Tampa Bay, Florida
Posted 21 September 2012 - 02:12 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.
read my post above. I used the quote to message you.
105 posts
Posted 21 September 2012 - 06: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
71 posts
Location
Tampa Bay, Florida
Posted 22 September 2012 - 05: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/>/>
15 posts
Location
The Netherlands
Posted 02 February 2013 - 07:52 AM
Yes this is just the information I needed. Thanks so much! :D/>