@Andrewsimpson4 Here’s another example of some input boxes. Just tap the box you want to select, type in a number. Tap another input box and enter a number. The total of the 4 boxes will be in the “Total” box. Not sure if this is what you’re after. Pressing return is not required.
displayMode(FULLSCREEN)
function setup()
showKeyboard()
iTab={}
table.insert(iTab,number(100,600,100,30,"number 1"))
table.insert(iTab,number(300,600,100,30,"number 2"))
table.insert(iTab,number(500,600,100,30,"number 3"))
table.insert(iTab,number(700,600,100,30,"number 4"))
end
function draw()
background(40,40,50)
for a,b in pairs(iTab) do
b:draw()
end
noFill()
stroke(255,0,0)
strokeWidth(2)
rect(400,500,100,30)
fill(255)
text("Total",400,540)
text(iTab[1].val+iTab[2].val+iTab[3].val+iTab[4].val,400,500)
end
function touched(t)
for a,b in pairs(iTab) do
if b:touched(t) then
return
end
end
end
number=class()
function number:init(x,y,w,h,txt)
self.x=x
self.y=y
self.w=w
self.h=h
self.txt=txt
self.val=0
self.sel=false
end
function number:draw()
rectMode(CENTER)
if self.sel then
if keyboardBuffer() ~= nil and keyboardBuffer() ~= "" then
self.val=tonumber(keyboardBuffer())
end
end
if self.val==nil then
self.val=0
end
fill(0)
if self.sel then
fill(85, 121, 125, 255)
end
stroke(255)
strokeWidth(2)
rect(self.x,self.y,self.w,self.h)
fill(255)
text(self.txt,self.x,self.y+self.h)
text(self.val,self.x,self.y)
end
function number:touched(t)
if t.state==BEGAN then
for z=1,#iTab do
iTab[z].sel=false
end
if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 and
t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
hideKeyboard()
showKeyboard()
self.sel=true
return true
end
end
end