Text over text problem

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)

You have a couple of alternatives. You can create these text objects once at the same time as everything else and either hide them (.alpha = 0) or set their .text = “”. Then just update the text within your button function.

Or you can create them each time, but before you do so, display.remove the old ones. Either way, you’ll need to declare the variables at the top of your file so you have a reference to grab within the button listener.

I think the easiest way is the last one: to set the text empty after and update the text within button function.

Lets try that. 

Thank you !

You have a couple of alternatives. You can create these text objects once at the same time as everything else and either hide them (.alpha = 0) or set their .text = “”. Then just update the text within your button function.

Or you can create them each time, but before you do so, display.remove the old ones. Either way, you’ll need to declare the variables at the top of your file so you have a reference to grab within the button listener.

I think the easiest way is the last one: to set the text empty after and update the text within button function.

Lets try that. 

Thank you !