Hello!
I’m playing around with Codea (again :)) ) and wanted to create a “pseudo” interactive program (ELIZA type).
I’ve been using a code from @sanit (http://twolivesleft.com/Codea/Talk/discussion/844/simple-keyboard-input-and-output/p1) and I wanted to draw questions and answers on the screen from corresponding tables.
I’ve tried different things without success. How can be accomplished that.
My up-to-now running code (which reads just one item from each table! 8-} ) is as follows:
function setup()
print("Touch to show Keyboard\
and press return to show a message")
q = {"What is your name?","What is your occupation?"} -- program's questions
a = {"I'm pleased to meet you ","That's an interesting job "} --program's answers
said = false
i=1
memory ={} -- this is for saving answers from user.
end
function draw()
background(255)
textMode(LEFT)
drawquestion(q[i]) -- drawing the questions
drawanswer(a[i]) -- drawing the answers
end
function drawquestion(pre)
text(pre,100,600)
w,h = textSize(pre)
if not said then
memory[i] = keyboardBuffer()
end
if memory[i] then
text(memory[i],100+w+10,600)
end
end
function drawanswer(res)
if i<3 and said then
text(res..memory[i],100,600- h)
end
end
function touched(touch)
if touch.state==ENDED then
showKeyboard()
said = false
end
end
function keyboard(key)
if key == "\
" then
hideKeyboard()
said =true
end
end