Howdy, Stranger!

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

User inputs a string

edited September 2012 in Questions Posts: 1

I am just starting and have been trying to figure out how to allow the user to input a string by using a text box or the like. Any ideas or direction?

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 7,924

    @BClife_brian

    Here is a simple example that you can get an idea from.


    function setup()     supportedOrientations(PORTRAIT)     str = ""     bcolor= 0     l=100     r=300     b=575     t=625 end function draw()     background(30,30,0,255)     stroke(255)     strokeWidth(6)     rectMode(CENTER)      textMode(CENTER)              fill(255)     text("Tap button then input data",WIDTH/2,800)     text("Press RETURN to show input in the output pane",WIDTH/2,750)         text("Enter value",200,650)          if bcolor == 0 then         fill(255, 0, 0, 255)     else         fill(128,0,0,255)     end     rect(200,600,200,50)             buffer = keyboardBuffer()    -- get keyed input          fill(255)     if buffer ~= nil then         text(buffer,200,600)    -- show input as it is keyed     else         text(str,200,600)     end end function touched()     if CurrentTouch.x > l and CurrentTouch.x < r then         if CurrentTouch.y > b and CurrentTouch.y < t then             showKeyboard()             bcolor = 1         end     end end function keyboard(key)     if key == RETURN then    -- return key pressed         str = buffer    -- move text into str         hideKeyboard()         bcolor = 0         print(str)    -- print str in output pane     end end
  • edited September 2012 Posts: 580

    Edit: oops, wrong thread!

  • .@BClife_brian - there is a textbox class provided with the example App Spritely. You can download a copy from http://codeatuts.blogspot.com.au/2012/07/tutorial-9-dependencies-libraries.html which also show how to use it or just extract it straight from the example.

  • edited September 2014 Posts: 20

    .

  • @BClife_brian You can also look here where someone has made a nice text box class.

  • Posts: 1,595

    @Famous this thread is 2 years old.. Why post a full stop?

  • @Luatee Lol I didn't notice the age, I just saw it at the top due to @Famous and replied.

Sign In or Register to comment.