Howdy, Stranger!

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

Wait for input text

edited September 2013 in Questions Posts: 97

Hi,

I have function where I need input 2 variable by using keyboard. I need to figure out how to "pause" or loop code to wait until I input all text. any ideas? Thanks

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 7,606

    @Cabernet Would something like this help.


    displayMode(FULLSCREEN) function setup()     str = ""     bcolor= 0     x=300     y=500     w=200     h=50     l=x-w/2    --button left     r=x+w/2    --right     b=y-h/2    --bottom     t=y+h/2    --top end function draw()     background(30,30,0,255)     strokeWidth(6)     rectMode(CENTER)      textMode(CENTER)             fill(255)     text("Tap button then input data",x,700)     text("Press RETURN to show input",x,650)         text("Enter value",x,550)        if bcolor == 0 then         fill(255, 0, 0, 255)     else         fill(128,0,0,255)     end         rect(x,y,w,h)    -- input area             fill(255)     if keyboardBuffer() ~= nil then         text(keyboardBuffer(),x,500)    -- show data as it is keyed     else         text(str,x,500)    -- show data in input area       end             text(str,x,450)    -- show data below input area end function touched() -- check if input area was 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) -- move keyboardBuffer to str when return is pressed     if key == RETURN then         str = keyboardBuffer()         hideKeyboard()         bcolor = 0     end end
  • Yes, this is simple solution but I need it without using draw() function...

  • Posts: 577

    @Cabernet why do you need it without draw() ?

  • edited September 2013 Posts: 500

    if you use a listener (checking state of something), those listeners always need to be up-to-date. so you have to use the draw() function anyway - there is no other way...

  • dave1707dave1707 Mod
    Posts: 7,606

    @Cabernet Here's a way of inputting 2 variables without using draw(). The 2 routines are setup to process the input only after the return key is pressed.


    function setup()     print("Input what you want in")     print("variable1 and variable2.")     print("Press return after each input.")     parameter.text("variable1",v1)     parameter.text("variable2",v2) end function v1()     l=string.len(variable1)     if string.sub(variable1,l)==RETURN then         variable1=string.sub(variable1,1,l-1)         print("do what you need here with\nvariable1 --  "..variable1)     end end function v2()     l=string.len(variable2)     if string.sub(variable2,l)==RETURN then         variable2=string.sub(variable2,1,l-1)         print("do what you need here with\nvariable2 --  "..variable2)     end end
  • dave1707dave1707 Mod
    Posts: 7,606

    @Cabernet Here's another way of inputting 2 variables without using draw().


    function setup()     print("Double tap screen for keyboard.")     print("Then enter variable 1 info")     inp=1     var1=""     var2=""     str="" end function touched(t) -- double tap screen to show keyboard     if t.tapCount==2 then         showKeyboard()     end end function keyboard(key) -- move keyboardBuffer to str when return is pressed     if key == RETURN then         str = keyboardBuffer()         if inp==1 then             var1=str             str=""             print("\nvariable 1 "..var1)             print("\nDouble tap screen for keyboard")             print("Then enter variable 2 info")             inp=2             hideKeyboard()         elseif inp==2 then             var2=str             str=""             inp=1             hideKeyboard()             print("\nvariable 2 "..var2)         end     end end
  • Thank you @dave1707!

Sign In or Register to comment.