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

help with basic "Else" Thanks!

Started by rubik3141, 11 November 2017 - 08:14 PM
rubik3141 #1
Posted 11 November 2017 - 09:14 PM
this is the program (i know it's stupid lol, it's my first program just tryna learn if, then, else)
http://prntscr.com/h98h7g
BUT:
http://prntscr.com/h98i62
when i say Bad… everything goes by plan…
http://prntscr.com/h98i1j
but when i say Fine, Thanks! it says invalid answer too… WHYYYYYYY
i tryed so hard to fix it myself but i just can't do it, it's like hours that i'm working on this stupid bug… pls help :C
Bomb Bloke #2
Posted 12 November 2017 - 02:15 AM
Instead of:

if info=="Fine, Thanks!" then
	textutils.slowPrint("Nice!")
end

if info=="Bad..." then
	textutils.slowPrint("I'm Sorry To Hear That...")
else
	textutils.slowPrint("Invalid Answer!")
end

… you'd want to do:

if info=="Fine, Thanks!" then
	textutils.slowPrint("Nice!")
elseif info=="Bad..." then
	textutils.slowPrint("I'm Sorry To Hear That...")
else
	textutils.slowPrint("Invalid Answer!")
end
rubik3141 #3
Posted 12 November 2017 - 03:37 PM
so if i want other answers i just need to put other elseif?
like, let's say i want an answer to be: i dont know
i just put…
if info=="Fine, Thanks!" then
textutils.slowPrint("Nice!")
elseif info=="Bad…" then
textutils.slowPrint("I'm Sorry To Hear That…")
elseif info=="I Don't Know" then
textutils.slowPrint("What ever i'd like to put here")
else

textutils.slowPrint("Invalid Answer!")
end
Bomb Bloke #4
Posted 12 November 2017 - 09:45 PM
Indeed.
Dave-ee Jones #5
Posted 17 November 2017 - 02:38 AM
This is a little off-topic but you can make it a bit easier for your code to detect what you've said by doing something like this:


if info:lower() == "fine, thanks!" then
  print("No problem.")
end

The ':lower()' makes the string in 'info' lowercase, so you can do all kinds of capitalisation combos in your string and it won't care. Just makes it a bit easier on you and your code. :)/>