People, I´m having a problem here.
I built a small calculator that works inputing a variable into a field and all other variables are calculated from the first one.
The program is working, the problem is that when I change values and click the calculate button, the new text will go over the old one and the values become unreadable.
How can i fix this?
I´ll place my code here:
Thanks in advance!
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- Your code here button = display.newImage("but.png") button.x = display.contentWidth/2 but.y = 450 cabecalho = display.newText( "KalKHOS", 50, 5 , native.systemFontBold , 20 ) cabecalho:setFillColor(1, 0.5, 0) local KOHtxt = display.newText( "KOH (g.)", 40, 50 , native.systemFontBold , 14 ) KOHtxt:setFillColor(1, 1, 1) local KOHx = native.newTextField( 70, 90, 120, 36 ) KOHx.inputType = "number" local Sulftxt = display.newText( "S (g.)", 35, 140 , native.systemFontBold , 14 ) Sulftxt:setFillColor(1, 1, 0) local Sulfx = "0" local Results = display.newText( "Results", 160, 220 , native.systemFontBold , 14 ) local Results2 = display.newText( "grams", 160, 240 , native.systemFontBold , 14 ) Results:setFillColor(0, 0.8, 0.7) Results2:setFillColor(0, 0.8, 0.7) local Sulf2txt = display.newText( "", 35, 160 , native.systemFontBold , 20 ) Sulf2txt:setFillColor(1, 1, 0) local drag= display.newImage("kh.jpg") drag.x=280 drag.y=10 function show() local Phi = 1.6 local KOHxNumber = tonumber (KOHx.text) or 0 local SulfxNumber = tonumber (Sulfx.text) or 0 if KOHxNumber \> SulfxNumber then Sulf2txt.text = (KOHxNumber \* Phi) print(Sulf2txt.text) local KO3 = SulfxNumber if SulfxNumber \< KOHxNumber then KO3 = KOHxNumber local A=((KO3/14)\*2) local B=((KO3/14)\*4) local C=((KO3/14)\*6) local D=((KO3/14)\*2) local firstP = display.newText( A, 80, 280 , native.systemFontBold , 14 ) firstP:setFillColor(0, 1, 0) local tx1 = display.newText("Start",180,280,native.systemFontBold , 14) tx1:setFillColor(0, 1, 0) local SecP = display.newText( B, 80, 300 , native.systemFontBold , 14 ) SecP:setFillColor(0, 0.5, 0.5) local tx2 = display.newText("Solution",180,300,native.systemFontBold , 14) tx2:setFillColor(0, 0.5, 0.5) local tercP = display.newText( C, 80, 320 , native.systemFontBold , 14 ) tercP:setFillColor(0.8, 0.8, 0.6) local tx3 = display.newText("Clearance",180,320,native.systemFontBold , 14) tx3:setFillColor(0.8, 0.8, 0.6) local fim = display.newText( D, 80, 340 , native.systemFontBold , 14 ) fim:setFillColor(1, 0, 0) local txf = display.newText("Finish",190,340,native.systemFontBold , 14) txf:setFillColor(1, 0, 0) end end end but:addEventListener("tap", show)