I have an issue with my code, the way it works is when a button is pressed then a function executes and then displays a value on the screen, and it does that. The problem is when the button is pressed again and a new value is displayed the old value does not go away. I have tried,
object:removeSelf() object = nil
but I get “attempt to call method ‘remove Self’ (a nil value)”
Here is the function
function resulter (d,c,s,dl,cl,sl) --rText.text = "" dbText:removeSelf() local r d = d \* dl c = c \* cl s = s \* sl r = (d + c) + s local resultIs print (r) resultIs = r if (resultIs) then dbText:removeSelf() dbText = nil end dbText = ("db Lossasass: " .. resultIs) local rText = display.newText (dbText, 0, 0, native.systemFont, 42) rText:setTextColor(255,255,255) rText.x = \_W \* .5 rText.y = \_H -100 end
and here is the sample text that is displayed before the function gets called.
--Result Text dbText = ("butt") rText = display.newText (dbText,0, 0,native.systemFont, 42) rText:setTextColor(255,255,255) rText.x = \_W \* .5 rText.y = \_H -100
When the function is called, the current text is supposed to be erased and the new text is supposed to replace it, but rather than replacing it, it simply appears over the old text.
Not sure what to do here.