Changing the object.text of a newEmbossedText display object

When I attempt to change the text of a newEmbossedText object, the last string that was assigned does not clear and the new value is superimposed over it, causing the display of the text to be unreadable.

I fixed it in one case by setting the object.text = “ “, first, And then assigning a new value.

Object.text = “not confused” and it worked.

For some reason, it is not working for me in a different case.

Here is how I have it set up.

local topMessage

local topMessageDisplay

topMessage is declared at the top of the Lua file and is later given a string value

topMessageDisplay is also declared at the top and will later be given the following.

topMessageDisplay = newEmbossedText(sceneGroup, topMessage, centerX, centerY, native.systemFont, 24)

Then, when I attempt to change topMessage,

topMessage = “confused”

And set

topMessageDisplay.text = topMessage

The last string value remains in addition to any subsequent values given to topMessage even when I assign topMessageDisplay.text = “ “

And then set,

topMessageDisplay.text = topMessage

Or even explicitly to,

TopMessageDisplay.text = “Help me!”

All previous strings assigned overlap one another and are unreadable.

I am utterly confused as I have a working case in one place, and then this mess!

I went through my code and compared the one case that works to the other case that does not, and unfortunately, I can’t see where one differs from the other.

Does anyone know what I may have done wrong?

I tried so many variations of fixes and I went in circles to no avail.

I can’t seem to clear the object.text

This has to be an easy fix.

I did it once before!

What am I missing?

Thanks in advance

Chris

I can’t know for certain without seeing your actual code, but if I had to guess, I’d wager you’re overwriting topMessageDisplay, so you lose reference to the original text object.

Since you’re adding the object to sceneGroup, I’m guessing you’re using Composer. Maybe you’re creating the object multiple times during scene events and the later topMessageDisplay.text = "something" assignments go to the last created object.

You can verify if that’s the case by adding a print( topMessageDisplay ) right after you’ve created the object. That’ll catch if you’re creating it multiple times. You can also add the following below the line where you update the text:

topMessageDisplay.text = topMessage
-- If the table reference is different, the object has been overwritten.
print( topMessageDisplay, topMessage )

Thanks XeduR!

I WAS recreating the embossed text object each time I was updating the message.

I wrongly assumed that the previous one would be overwritten. Or, I just didn’t know what the hell I was doing.

A bit of both to be fair. :slight_smile:

I can’t believe I actually have a working game (on my lap top), verbose as the code may be for a newbie like me, and I can still be stumped by simple issues such as this.

So, I guess that’s what they call a memory leak, or something to that effect. Where I have orphan display objects taking up space, because I did not properly dispose of them?

I figured the fact that the text was not clearing, something would jump out to a seasoned Corona/Solar2D programmer such as your self.

Thanks for your time, and thanks for pointing out the obvious!

I didn’t know what I did wrong, but I knew the solution would be swift.

Too cool!

Thanks again

Chris

1 Like