What is your name?

I’m wondering how to make a program where if it asked the user what there name is and they entered there name, the program would then print what the name given by the user. How can I do this?

create a text box (search the forums there’s a view examples) and get the text from the users input and print it, do you want me to elaborate?

Edit: @Dave1707 ninja time coding!

@kirorp Here’s a simple example. Press return after entering something.


function setup()
    showKeyboard()
    tab={}
    str=""
end

function draw()
    background(40,40,50)
    fill(255)
    text("Enter your name",WIDTH/2,HEIGHT/2+50)
    str=keyboardBuffer()
    if rtn then
        rtn=false
        hideKeyboard()
        showKeyboard()
    end
    text(str,WIDTH/2,HEIGHT/2) 
end

function keyboard(k)
    if k==RETURN then
        rtn=true
        print(str)
    end 
end

@kirorp Here’s the above program with boxes.

EDIT: Modified the below code to show shadows.


function setup()
    rectMode(CENTER)
    showKeyboard()
    tab={}
    str=""
end

function draw()
    background(80,80,80)
    
    fill(0)
    noStroke()
    rect(WIDTH/2+10,HEIGHT/2+90,200,50)
    rect(WIDTH/2+10,HEIGHT/2-10,200,50)
    
    fill(255)
    stroke(255,0,0)
    strokeWidth(5)
    rect(WIDTH/2,HEIGHT/2+100,200,50)
    
    fill(150,150,150)
    stroke(255)
    strokeWidth(5)    
    rect(WIDTH/2,HEIGHT/2,200,50)
    
    fill(255,0,0)
    text("Enter your name.",WIDTH/2,HEIGHT/2+100)
    
    str=keyboardBuffer()
    if rtn then
        rtn=false
        hideKeyboard()
        showKeyboard()
    end
    
    fill(255)
    text(str,WIDTH/2,HEIGHT/2) 
end

function keyboard(k)
    if k==RETURN then
        rtn=true
        print(str)
    end 
end

Edited @dave1707’s example to show the keyboard upon pressing the lower rectanlge and displaying the entered name into the upper rectangle, tho this is not the question, sorry if you guys think it’s to much


function setup()
    rectMode(CENTER)
    showKeyboard()
    tab={}
    str=""
    strDisp = "Enter your name."
end

function draw()
    background(80,80,80)
    
    fill(0)
    noStroke()
    rect(WIDTH/2+10,HEIGHT/2+90,200,50)
    rect(WIDTH/2+10,HEIGHT/2-10,200,50)
    
    fill(255)
    stroke(255,0,0)
    strokeWidth(5)
    rect(WIDTH/2,HEIGHT/2+100,200,50)
    
    fill(150,150,150)
    stroke(255)
    strokeWidth(5)    
    rect(WIDTH/2,HEIGHT/2,200,50)
    
    fill(255,0,0)
    text(strDisp,WIDTH/2,HEIGHT/2+100)
    
    str=keyboardBuffer()
    if rtn then
        rtn=false
        hideKeyboard()
        showKeyboard()
    end
    
    fill(255)
    text(str,WIDTH/2,HEIGHT/2) 
end

function keyboard(k)
    if k==RETURN then
        rtn=true
        print(str)
        strDisp = str
    end 
end

function touched(t)
    
    if t.state == ENDED then
        if math.abs(t.x - WIDTH/2) <= 100 and math.abs(t.y - HEIGHT/2) <= 25 then
            showKeyboard()
        end
    end
    
end

Thanks everyone, I see now how to get the program to print the text into the output and on the screen

@All LOL! It’s the Pyramid of Helpfulness. :smiley: =D>