Help with some keyboard and table stuff

hello everyone, I am having some problems with my code, so, what am i trying to do is to type each box and set a text into it, but everytime i set a text and change to another box, the text dissapears or it changes to the box i pressed :frowning:
Here is some of the code

self.buffer = keyboardBuffer()
textWrapWidth(w-4)
if self.buffer then
for i=1, #C do
if CurrentTouch.x>C[i][1] and CurrentTouch.x<C[i][1]+w and
CurrentTouch.y>C[i][2] and CurrentTouch.y<C[i][2]+h then
if C[i][6] == nil then --spot 6 got no value atm
C[i][6]=0
end
text( C[i][6], C[i][1]+w/2, C[i][2]+h/2 )
C[i][6]=(self.buffer)
end
end
end
popStyle()

@CarlosSando Here’s an example of what you’re trying to do. It uses a class, but I don’t know if you know how to use classes yet. Tap a box, then type some text. If you have any questions, just ask.

function setup()
    rectMode(CENTER)
    bTab={}
    table.insert(bTab,box(300,700))
    table.insert(bTab,box(300,600))
    table.insert(bTab,box(300,500))
end

function draw()
    background(40, 40, 50)
    for a,b in pairs(bTab) do
        b:draw()
    end
end

function touched(t)
    for a,b in pairs(bTab) do
        b:touched(t)
    end
end

function keyboard(k)
    for a,b in pairs(bTab) do
        b:keyboard(k)
    end
end

box=class()

function box:init(x,y)
    self.x=x
    self.y=y
    self.txt=""
    self.sel=false
end

function box:draw()
    fill(255)
    if self.sel then
        fill(209, 228, 226, 255)
    end
    rect(self.x,self.y,100,50)
    fill(255,0,0)
    text(self.txt,self.x,self.y)    
end

function box:touched(t)
    if t.state==BEGAN then
        showKeyboard()
        self.sel=false
        if t.x>self.x-50 and t.x<self.x+50 and t.y>self.y-25 and t.y<self.y+25 then
            self.txt=""
            self.sel=true
            return
        end
    end  
end

function box:keyboard(k)
    if self.sel then
        if k==RETURN then
            hideKeyboard()
            self.sel=false
        elseif k==BACKSPACE then
            self.txt=string.sub(self.txt,1,#self.txt-1)        
        else
            self.txt=self.txt..k 
        end
    end       
end

@dave1707 Thanks for this - not used the keyboard before and was just about to go digging - very timely for me

@West That’s the purpose of this forum. One person asks a question and many others also benefit.