Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Text input for pseudo-AI [Solved]

edited September 2013 in Questions Posts: 226

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\nand 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 == "\n" then hideKeyboard() said =true end end

Comments

  • dave1707dave1707 Mod
    edited September 2013 Posts: 8,579

    @quezadav Try changing touched to this. There's still an error after the last question.


    function touched(touch)     if touch.state==ENDED then         showKeyboard()         if said then             i=i+1         end         said = false     end end
  • dave1707dave1707 Mod
    edited September 2013 Posts: 8,579

    @quezadav Change draw to this to stop the error from the above code.


    function draw()     background(255)     textMode(LEFT)     if i<3 then         drawquestion(q[i]) -- drawing the questions         drawanswer(a[i]) -- drawing the answers     end end
  • Wow! That was the fastest working help in all Codealand :-O
    Many thanks!

  • dave1707dave1707 Mod
    Posts: 8,579

    @quezadav Change these functions so the if statement depends on the size of q .


    function draw()     background(255)     textMode(LEFT)     if i<=#q then         drawquestion(q[i]) -- drawing the questions         drawanswer(a[i]) -- drawing the answers     end end function drawanswer(res)     if said then         text(res..memory[i],100,600- h)     end end
  • OK. Thanks again.

Sign In or Register to comment.