setText broken v 1082

Has the ‘setText’ method disappeared from display.newText.

I was using it a lot to change the onscreen text, in recent build it now fires error - attempt to call method ‘setText’ (a nil value)

    local t = display.newText( 'hello', 0,0, \_S.ui.boldFont, 10 )      t.x, t.y = 100,100      t:setText('goodbye')  

I"m getting the same issue.  Can you zip up that small sample and file a bug report using the “Report a bug” link above?

Thanks

Rob

done

I"m getting the same issue.  Can you zip up that small sample and file a bug report using the “Report a bug” link above?

Thanks

Rob

done

Me three.   Glad to know it’s just a bug and not a deprecated method.   Predictive iDash uses that call 83 times.  

FYI, I’m seeing it in 1076, not 1082.

Well you should be able to just set the .text attribute directly.

mytext.text = “fred”

and skip the setText() APi call.

I can confirm that mytext.text = “fred” approach works well in current builds. 

So is Corona fixing this or do I need to change my code?   I realize I can use the .text member, but it doesn’t seem like good practice to just remove API’s.

Display.newText() has had some history with it going back to the display.newRetinaText and the first implementations of display.newEmbossedText() which required the setText() method since it was doing more than just sticking the value in an attribute.  Today, display.newEmbossedText() still needs the setText() method, but for display.newText, it doesn’t serve a point. Treat it as deprecated and stop using it would be my suggested advice.  There is nothing to fix.

If there is nothing to fix, why tell the OP to open a bug report?   If/when I upgrade, I’ll use the workaround, but publishing and subsequently taking away API’s without warning…kind of sucks.

I think there’s a bit of confusion here.

I’m pretty sure that the object returned by display.newText() has never supported a setText() function.

Just to double check, I looked at the last 2 years of changes made to our text object code.  No setText() function ever existed within that time span.  And to triple check, I tried calling setText() via the Corona Simulator using build #971 and #1076… which produced a Lua runtime error, as expected since the function does not exist.

As Rob has mentioned, I think you may be referring to display.newEmbossedText() and the deprecated display.newRetinaText(). The objects returned by those functions do have setText() functions.  In fact, that is the only means of changing their text.  But I’m quite positive display.newText() never had that function.

I’m using build 922.   In my current project, I use setText only a half-dozen times and mostly in my level editor, but I’ve double and triple checked that I’m not defining a setText function and adding it to the returned text object.   I had actually done that with Predictive iDash, but not in my current project.   

On the other hand, it must be something in my code/environment, because if I run a simple example with a single display.newText object using the same 922 build, it throws the runtime error on setText().   

It’s a mystery, but not a very exciting one, I guess :slight_smile:

Apologies for my rude reply to Rob earlier in the thread.

It is strange though that newEmbossedText() and newText() have different ways for updating the text. Can we get newEmbossedText() to allow changing the text using .text so that the APIs are the same?

davemikesell,
 
If it helps you any, you can add a setText() function to the returned text object like this…
 

local myText = display.newText("Hello World", 0, 0, native.systemFont, 10) myText.setText = function(object, text) object.text = text end myText:setText("This is my new text!")

 
I’m guessing that your app might have been using a Lua library at one point that was doing exactly the above.  Not really sure, but this is one of the cool features of Lua.

In any case, I hope my above post didn’t come across as argumentative.  I just wanted to demonstrate that we were taking this matter seriously and double check the code on our end to make sure we didn’t take anything away.  I’m glad this matter is resolved and I hope my above code snippet might help save you some time without rewriting huge amounts of code.

Thanks, Joshua.   Your post didn’t seem argumentative at all to me.    No worries.

The method you suggest is exactly what I do in another app (I wrote a wrapper to display.newText that added the setText function), but not this one, which is why this is a head-scratcher.    There has to be something in my environment that’s adorning this text object with setText, I just can’t figure out what.   I’ll let you know if/when I do.   

The reason it is inconsistent is because the display.newEmbossedText() is completely implemented in Lua versus display.newText() is completely implemented in C/C++.  It is not so easy to override the reading/writing of a table’s fields in pure Lua, which is what these functions really return.  I don’t like the inconsistency either, but that’s just how it is.

Me three.   Glad to know it’s just a bug and not a deprecated method.   Predictive iDash uses that call 83 times.  

FYI, I’m seeing it in 1076, not 1082.

Well you should be able to just set the .text attribute directly.

mytext.text = “fred”

and skip the setText() APi call.

I can confirm that mytext.text = “fred” approach works well in current builds.