Help with buttons Buttons

Hello, 

I am a beginner and i’m trying to create a button when a specific function is called. 

It is basically like the button is displayed when the function is called and as soon as the button is clicked it should dissapear from the scene!

I’m new to LUA and Corona so, i’m sorry if i got the basics wrong or am missing something really obvious!

Code is something like this: 

– function declaration 

local function timerOver( event)

      print( “timer over” )

      titleDisp.text = “Vote! Sucess or Failure”

      – Create Button here (or maybe enable it here)

end

– function call

timer.performWithDelay( 15000, timerOver)

try this 

local widget = require("widget") local cx = display.contentCenterX local cy = display.contentCenterY local voteButton local titleDisp local function onVoteButton(e) if e.phase == "ended" then display.remove(voteButton) voteButton = nil display.remove(titleDisp) voteButton = nil -- or just hide both (or either) the text and button -- just make them invisible -- you must remark-out the 4 lines above if just hiding these display objects --voteButton.isVisible = false --titleDisp.isVisible = false end end local function timerOver( event) print( "timer over" ) titleDisp.text = "Vote! Sucess or Failure" -- Create Button here (or maybe enable it here) voteButton = widget.newButton{ defaultFile = "Textures/Buttons/button.png", overFile = "Textures/Buttons/button\_Dn.png", width = 100, height = 30, onEvent = onVoteButton } voteButton.x = cx voteButton.y = cy end titleDisp = display.newText("", cx, cy - 75, nil, 24) -- function call -- delaying the function call for 15 seconds timer.performWithDelay( 15000, timerOver)

also check out this links about newText and newButton

https://docs.coronalabs.com/api/library/display/newText.html

https://docs.coronalabs.com/api/library/widget/newButton.html

Good luck!

Bob

Yes, it worked, thank you so much, you are my savior, Bob! 

try this 

local widget = require("widget") local cx = display.contentCenterX local cy = display.contentCenterY local voteButton local titleDisp local function onVoteButton(e) if e.phase == "ended" then display.remove(voteButton) voteButton = nil display.remove(titleDisp) voteButton = nil -- or just hide both (or either) the text and button -- just make them invisible -- you must remark-out the 4 lines above if just hiding these display objects --voteButton.isVisible = false --titleDisp.isVisible = false end end local function timerOver( event) print( "timer over" ) titleDisp.text = "Vote! Sucess or Failure" -- Create Button here (or maybe enable it here) voteButton = widget.newButton{ defaultFile = "Textures/Buttons/button.png", overFile = "Textures/Buttons/button\_Dn.png", width = 100, height = 30, onEvent = onVoteButton } voteButton.x = cx voteButton.y = cy end titleDisp = display.newText("", cx, cy - 75, nil, 24) -- function call -- delaying the function call for 15 seconds timer.performWithDelay( 15000, timerOver)

also check out this links about newText and newButton

https://docs.coronalabs.com/api/library/display/newText.html

https://docs.coronalabs.com/api/library/widget/newButton.html

Good luck!

Bob

Yes, it worked, thank you so much, you are my savior, Bob!