I am creating a small program to show off to my friends…. This is my first program, so I need lots of help.
My Problem:
I have text, a question, but how do I make a certain answer when you put in a certain line, like Noah? This is my code so far…
local background = display.newImage( "white.png" )
local text = display.newText( "Hello!", 25, 65, "Helvetica", 22 )
text:setTextColor( 0, 128, 0 )
local text = display.newText( "What is your name?", 25, 100, "Helvetica", 22 )
text:setTextColor( 0, 128, 0 )
local answer
repeat
io.write("What is your name?")
io.flush()
answer=io.read()
until answer=="Emmy" or answer=="Mom" or answer=="Dad" or answer=="Noah"
I am trying out Corona SDK and it just keeps repeating “What is your name?”
What shall I do?
I’d code the responses in a table. like this:
This will look up the answer in the
responsestable, and return the requested answer if the person matches.Note, this logic will work for prompting and answering on the standard in and output. For GUI stuff (like Corona probably uses) you should use some of their functions or methods. I can imagine that the text objects generated with the
newText()function might have a changeText (or value, or whatever method) to change the displayed text.