Hi people!
This post is the following post from:
http://twolivesleft.com/Codea/Talk/discussion/3617/ai-chatbox#Item_7
I use the following two codes for my program, but I am unable to combine them.
I’ve tried anything, but have to admit that my knowledge is too short.
When I can combine the “menu” with the " conversation" this little project is good to go ( I suppose)!
The screen/menu:
displayMode(FULLSCREEN)
function setup()
s1=screen1()
s2=screen2()
s3=screen3()
s=1
end
function draw()
fontSize(40)
if s==1 then
s1:draw()
end
if s==2 then
s2:draw()
end
if s==3 then
s3:draw()
end
end
function touched(t)
if t.state==BEGAN then
s=s+1
if s>3 then
s=1
end
end
end
screen1=class()
function screen1:init()
end
function screen1:draw()
background(255, 220, 0, 94)
fill(255,0,0)
text("screen 1",WIDTH/2,HEIGHT/2)
text("tap screen for next screen",WIDTH/2,HEIGHT/2-200)
end
screen2=class()
function screen2:init()
end
function screen2:draw()
background(95, 255, 0, 95)
fill(255,0,0)
text("screen 2",WIDTH/2,HEIGHT/2)
text("tap screen for next screen",WIDTH/2,HEIGHT/2-200)
end
screen3=class()
function screen3:init()
end
function screen3:draw()
background(0, 255, 239, 95)
fill(255,0,0)
text("screen 3",WIDTH/2,HEIGHT/2)
text("tap screen for next screen",WIDTH/2,HEIGHT/2-200)
end
The chat, basic:
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)
if i<3 then
drawquestion(q[i]) -- drawing the questions
drawanswer(a[i]) -- drawing the answers
end
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()
if said then
i=i+1
end
said = false
end
end
function keyboard(key)
if key == "\
" then
hideKeyboard()
said =true
end
end
I hope this question isn’t because I am too unexperienced.
The above codes are unaltered versions from topics on this forum, although I know how to change them.
Combining them would solve my startup issues.
ps: The .lua code from Eliza isn’t compatible with codea.
ps2: Thank you so much in advance, again!
Regards