Howdy, Stranger!

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

Output / input

edited August 2013 in Questions Posts: 51

So I am partially new to coding and my brother who is older than me codes on python, and he can use output and have the user type in the output and if it equals something he make it do something... Anyways.. I was wondering if codea offers someway of having a user be able to get to a keyboard and type something. Thanks for the help!

Comments

  • IgnatzIgnatz Mod
    Posts: 5,396

    sorry, this isn't very clear. Can you try to explain it again?

  • dave1707dave1707 Mod
    edited August 2013 Posts: 6,828

    Is this something like what you're asking. There isn't an input command, you have to use the keyboard function.


    displayMode(FULLSCREEN) function setup()     hideKeyboard()     str=""     data=0 end function draw()     background(40,40,50)     rectMode(CENTER)     fill(255)     text("tap screen for keyboard",WIDTH/2,550)     text("input data then press RETURN",WIDTH/2,500)     if keyboardBuffer() ~= nil then         str=keyboardBuffer()     end     text("data  "..data,WIDTH/2,650)     rect(WIDTH/2,600,200,50)     fill(255,0,0)     text(str,WIDTH/2,600) end function keyboard(k)     if k==RETURN then         hideKeyboard()         data=str         if data=="" or data==nil then             data=0         end     end   end function touched(t)     if t.state==BEGAN then         showKeyboard()     end end
  • ^yes thank you

  • ^^but wait how would I make it so if I input something it does something?:
    If data=="hello" then
    Text("hello",WIDTH/2,HEIGHT 700)

  • dave1707dave1707 Mod
    edited August 2013 Posts: 6,828

    @Wallisch_pls You had the code right, you just needed to put it someplace. See below. Just type hello.


    displayMode(FULLSCREEN) function setup()     hideKeyboard()     str=""     data=0 end function draw()     background(40,40,50)     rectMode(CENTER)     fill(255)     text("tap screen for keyboard",WIDTH/2,550)     text("input data then press RETURN",WIDTH/2,500)     if keyboardBuffer() ~= nil then         str=keyboardBuffer()     end     text("data  "..data,WIDTH/2,650)     rect(WIDTH/2,600,200,50)     fill(255,0,0)     text(str,WIDTH/2,600)          if data=="hello" then          text("hello",WIDTH/2,HEIGHT-50)     end end function keyboard(k)     if k==RETURN then         hideKeyboard()         data=str         if data=="" or data==nil then             data=0         end     end   end function touched(t)     if t.state==BEGAN then         showKeyboard()     end end
  • Posts: 1,976

    Small rewrite to the keyboard function to add backspace support:

    function keyboard(key)
        if key == BACKSPACE then
            data = string.sub(data, 1, string.len(data) - 1)
        elseif key == RETURN then
            hideKeyboard()
            data = str
            if data == "" or data == nil then
                data = 0
            end
        end
    end
    
  • dave1707dave1707 Mod
    Posts: 6,828

    @SkyTheCoder The backspace key works in my original program the way it's coded now.

Sign In or Register to comment.