@TravisBevan Just in case you’re still looking for database code, here’s a limited example I have. This will give you an idea of the amount of code that’s required for something simple. There aren’t any edit checks, so it might crash at times. To input something, just tap on a field. Tap on Save to save the info. Tap Read to look at the entries. Tap Delete to delete an entry. The info is saved as a text file in the Dropbox folder. You can change the code to add or delete the number of input fields or change their names.
displayMode(FULLSCREEN)
function setup()
fileName="Dropbox:tab1"
rectMode(CENTER)
dtab={}
-- input tabs
table.insert(dtab,input("i",WIDTH/2,HEIGHT-100,300,40,"Name"))
table.insert(dtab,input("i",WIDTH/2,HEIGHT-150,300,40,"Address"))
table.insert(dtab,input("i",WIDTH/2,HEIGHT-200,300,40,"City"))
table.insert(dtab,input("i",WIDTH/2,HEIGHT-250,300,40,"State"))
table.insert(dtab,input("i",WIDTH/2,HEIGHT-300,300,40,"Phone"))
table.insert(dtab,input("i",WIDTH/2,HEIGHT-350,300,40,"Email"))
table.insert(dtab,input("i",WIDTH/2,HEIGHT-400,300,40,"Misc"))
-- show tabs
table.insert(dtab,input("s",120,HEIGHT-50,130,40,"Rec #",show))
-- functions tabs
table.insert(dtab,input("f",WIDTH-500,HEIGHT-50,70,40,"Read",read))
table.insert(dtab,input("f",WIDTH-400,HEIGHT-50,70,40,"Save",save))
table.insert(dtab,input("f",WIDTH-300,HEIGHT-50,70,40,"New",new))
table.insert(dtab,input("f",WIDTH-200,HEIGHT-50,70,40,"Delete",delete))
showKeyboard()
cnt=0
val=readText(fileName)
if val==nil then
qtab={}
else
qtab=json.decode(val)
end
end
function draw()
background(40, 40, 50)
for d=1,#dtab do
dtab[d]:draw()
end
end
function keyboard(k)
for d=1,#dtab do
dtab[d]:keyboard(k)
end
end
function touched(t)
if not isKeyboardShowing() then
showKeyboard()
end
for d=1,#dtab do
dtab[d]:touched(t)
end
end
function read()
for z=1,#dtab do
dtab[z].str=""
end
cnt=cnt+1
if cnt>#qtab then
cnt=0
else
for z=1,#dtab do
dtab[z].str=qtab[cnt][z]
end
end
end
function save()
cnt=0
f=#qtab+1
qtab[f]={}
for z=1,#dtab do
if dtab[z].type=="i" then
qtab[f][z]=dtab[z].str
dtab[z].str=""
end
end
val=json.encode(qtab)
saveText(fileName,val)
end
function delete()
table.remove(qtab,cnt)
for z=1,#dtab do
dtab[z].str=""
end
val=json.encode(qtab)
saveText(fileName,val)
cnt=0
end
function update()
for z=1,#dtab do
qtab[cnt][z]=dtab[z].str
dtab[z].str=""
end
val=json.encode(qtab)
saveText(fileName,val)
cnt=0
end
function new()
for z=1,#dtab do
dtab[z].str=""
end
cnt=0
end
function show(self)
fill(255)
str=self.name.." "..cnt.." of "..#qtab
text(str,self.x,self.y)
end
input = class()
function input:init(t,x,y,w,h,n,f)
self.type=t
self.x=x
self.y=y
self.width=w
self.height=h
self.name=n
self.left=x-self.width/2
self.right=x+self.width/2;
self.bottom=y-self.height/2
self.top=y+self.height/2
self.str=""
self.selected=false
self.func=f or function() end
end
function input:draw()
strokeWidth(0)
local cur=""
if self.selected then
stroke(255,0,0)
strokeWidth(4)
cur="_"
end
fill(123, 185, 215, 255)
rect(self.x,self.y,self.width,self.height)
if self.type=="s" then
self.func(self)
elseif self.str~="" and self.str~=nil then
fill(10, 9, 9, 255)
text(self.str..cur,self.x+2,self.y)
else
fill(255)
text(self.name,self.x,self.y)
end
end
function input:touched(t)
if t.state==BEGAN then
if t.x>self.left and t.x<self.right and
t.y>self.bottom and t.y<self.top then
for c=1,#dtab do
dtab[c].selected=false
end
if self.type=="i" then
self.selected=true
self.str=""
elseif self.type=="f" then
self.func()
end
end
end
end
function input:keyboard(k)
if self.selected then
if k==RETURN then
self.selected=false
elseif k==BACKSPACE then
self.str=string.sub(self.str,1,#self.str-1)
else
self.str=self.str..k
end
end
end