change text with a button

Hi guys.

I contact you cause i want change a text with a button. I tried but the code doesn’t run. 

Here the code

local number = math.random (10)

local text = display.newText(number, 420, 25, “Arial”, 24)

text.x = 340

text.y = 30

local button = display.newImage(“play1.png”)

   button.x = 300

   button.y =50

   button.xScale = 0.1

   button.yScale = 0.1

local function changeText(event)

   if event.phase==“ended” then

   number = math.random (10)

  

   button:removeEventListener( “touch”, changeText )

   end

end

button:addEventListener( “touch”, changeText )

I tried to change position (to test the code) and the code run, 

Hi @marcomm3007,

In your listener function, you’re changing the value of “number”, but you’re not doing anything to the text object “text”. You need to set its .text property to something different (in this case, the new value of “number”).

Please see here:

http://docs.coronalabs.com/api/type/TextObject/text.html

Best regards,

Brent

Hi @marcomm3007,

In your listener function, you’re changing the value of “number”, but you’re not doing anything to the text object “text”. You need to set its .text property to something different (in this case, the new value of “number”).

Please see here:

http://docs.coronalabs.com/api/type/TextObject/text.html

Best regards,

Brent