Wait for input text

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

@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…

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

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…

@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\
variable1 --  "..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\
variable2 --  "..variable2)
    end
end

@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("\
variable 1 "..var1)
            print("\
Double tap screen for keyboard")
            print("Then enter variable 2 info")
            inp=2
            hideKeyboard()
        elseif inp==2 then
            var2=str
            str=""
            inp=1
            hideKeyboard()
            print("\
variable 2 "..var2)
        end
    end
end

Thank you @dave1707!