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
0
4 replies to this topic
#1
Posted 11 November 2017 - 09:14 PM
#2
Posted 12 November 2017 - 02:15 AM
Instead of:
... you'd want to do:
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
#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
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
#4
Posted 12 November 2017 - 09:45 PM
Indeed.
#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:
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.
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.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users