Multiple Keyboard inputs help

I recently found an old project that i was making a year ago, and since i have not wrote anything in a while, im a bit confused :frowning: .
What i was trying to do is an algebric calculator that uses bhaskara to solve equations.
Here is what i was able to do.

function Results:init(x)
    showKeyboard() 
end

function Results:draw()
    buffer = keyboardBuffer()
    if buffer then
        buffer = tbuffer{a,b,c}
        d = math.pow(b,2)- 4 * a * c
        x1 = (-b + math.sqrt(d))/2*a
        x2 = (-b-math.sqrt(d))/2*a
        fill(255)
        fontSize(40)
        font("AmericanTypewriter-Bold")
        textWrapWidth(WIDTH)   
        text(a.."x^2+"..b.."x+" ..c.. " = 0", WIDTH/2,HEIGHT -100)
        fill(255, 0, 0, 255)
        text("Delta = "..b.."^2 - 4*"..a.."*"..c,WIDTH/2,HEIGHT -150)
        text("Delta = "..b*b.." - "..4*a*c,WIDTH/2,HEIGHT -200)
        text("Delta = "..d,WIDTH/2, HEIGHT-250)
        fill(0, 21, 255, 255)
        text("X1 = ",201,HEIGHT -315)
        text(-b.."+".."?"..d,WIDTH/2,HEIGHT-300)
        text("____________",WIDTH/2,HEIGHT-300)
        text("2 * "..a,WIDTH/2,HEIGHT-340)
        text("X1 = ",201,HEIGHT-405)
        text(-b.."+"..math.sqrt(d),WIDTH/2,HEIGHT-390)
        text("____________",WIDTH/2,HEIGHT-390)
        text(2*a,WIDTH/2,HEIGHT-430)
        text("X1 = "..x1,WIDTH/2,HEIGHT-480)
        fill(255, 158, 0, 255)
        text("X2 = ",201,HEIGHT -545)
        text(-b.."-".."?"..d,WIDTH/2,HEIGHT-530)
        text("____________",WIDTH/2,HEIGHT-530)
        text("2 * "..a,WIDTH/2,HEIGHT-570)    
        text(-b.."-"..math.sqrt(d),WIDTH/2,HEIGHT-620)
        text("____________",WIDTH/2,HEIGHT-620)
        text(2*a,WIDTH/2,HEIGHT-660)
        text("X2 = ",201,HEIGHT -635)
        text("X2 = "..x2,WIDTH/2,HEIGHT-710)
    end
end

What i inteded here is to input for example 1,-6,5 and it would return a=1,b=-6,c=5.
The program says tbuffer = nil, and i dont know how to get multiple values from the keyboard.
Sorry for the messy code, its my first one

. @PLPP Try this. You’ll have to change the code for how you want it.


function setup()
end

function keyboard(k)
    if k==RETURN then
        buffer=keyboardBuffer()
        a,b,c=string.match(buffer,"(%d+),(%d+),(%d+)")
        hideKeyboard()
        if a~=nil and b~=nil and c~=nil then
            show=true
        else
            show=false
        end
    end  
end

function touched(t)
    if t.state==BEGAN then
        showKeyboard()
        show=false
    end
end

function draw()
    background(40,40,50)
    if show then
        d = math.pow(b,2)- 4 * a * c
        x1 = (-b + math.sqrt(d))/2*a
        x2 = (-b-math.sqrt(d))/2*a
        fill(255)
        fontSize(40)
        font("AmericanTypewriter-Bold")
        textWrapWidth(WIDTH)   
        text(a.."x^2+"..b.."x+" ..c.. " = 0", WIDTH/2,HEIGHT -100)
        fill(255, 0, 0, 255)
        text("Delta = "..b.."^2 - 4*"..a.."*"..c,WIDTH/2,HEIGHT -150)
        text("Delta = "..b*b.." - "..4*a*c,WIDTH/2,HEIGHT -200)
        text("Delta = "..d,WIDTH/2, HEIGHT-250)
        fill(0, 21, 255, 255)
        text("X1 = ",201,HEIGHT -315)
        text(-b.."+".."?"..d,WIDTH/2,HEIGHT-300)
        text("____________",WIDTH/2,HEIGHT-300)
        text("2 * "..a,WIDTH/2,HEIGHT-340)
        text("X1 = ",201,HEIGHT-405)
        text(-b.."+"..math.sqrt(d),WIDTH/2,HEIGHT-390)
        text("____________",WIDTH/2,HEIGHT-390)
        text(2*a,WIDTH/2,HEIGHT-430)
        text("X1 = "..x1,WIDTH/2,HEIGHT-480)
        fill(255, 158, 0, 255)
        text("X2 = ",201,HEIGHT -545)
        text(-b.."-".."?"..d,WIDTH/2,HEIGHT-530)
        text("____________",WIDTH/2,HEIGHT-530)
        text("2 * "..a,WIDTH/2,HEIGHT-570)    
        text(-b.."-"..math.sqrt(d),WIDTH/2,HEIGHT-620)
        text("____________",WIDTH/2,HEIGHT-620)
        text(2*a,WIDTH/2,HEIGHT-660)
        text("X2 = ",201,HEIGHT -635)
        text("X2 = "..x2,WIDTH/2,HEIGHT-710)

    else
        fill(255)
        fontSize(40)
        font("AmericanTypewriter-Bold")
        textWrapWidth(WIDTH)   
        text("Enter 3 numbers seperated by a comma then press return",WIDTH/2,HEIGHT/2)
    end
    fill(255,0,0)
    text("tap screen for keyboard",WIDTH/2,HEIGHT-900)
end

Thank you!!! It works! The only problem is that it doesnt accept negative numbers like 1,-6,5

Thank you!!! It works! The only problem is that it doesnt accept negative numbers like 1,-6,5. I tried using

        a,b,c=string.match(buffer,"(%d+),(%d+),(%d+)",-20)

(Sorry for double post)

. @PLPP Sorry, replace the existing line with this one to accept negative numbers.

a,b,c=string.match(buffer,“([-?]%d+),([-?]%d+),([-?]%d+)”)

EDIT: The above still doesnt work right. Working on the correct layout.

EDIT: Try this one.

a,b,c=string.match(buffer,“([±]?%d+),([±]?%d+),([±]?%d+)”)

Now it doesnt works with positive numbers
Edit:
Now it works! Thank you!

.@PLPP Replace the else section in draw with this code. You can then see what’s being entered and you can use the backspace key to make input changes.


else
        rectMode(CENTER)
        fill(255)
        rect(WIDTH/2,900,300,50)
        fill(0,255,0)
        text(keyboardBuffer(),WIDTH/2,900)
        fill(255)
        fontSize(40)
        font("AmericanTypewriter-Bold")
        textWrapWidth(WIDTH)   
        text("Enter 3 numbers seperated by a comma then press return",WIDTH/2,HEIGHT/2)
end

Thank you again, i tried making it myself but yours is way better( sorry for the delay, i was out of town)

        fill(255)
        fontSize(38)
        font("AmericanTypewriter-Bold")
        textWrapWidth(WIDTH)
        text("Enter 3 numbers seperated by a comma then press return:"..keyboardBuffer(),WIDTH/2,HEIGHT -94)