reload scene not working in a pause menu- code attached

trying to make a pause screen for my game with a reload button to start over the “level” but it is just not working.  Code attached.  any help appreciated

[lua]local function onpauseBtnPress()

    

    local myRoundedRect = display.newRoundedRect(134, 201, 500, 350, 12)

    myRoundedRect.strokeWidth = 8

    myRoundedRect:setFillColor(214, 214, 214)

    myRoundedRect:setStrokeColor(111, 111, 111)

    local pauseLabel = display.newText(“Paused”, 0, 225, native.systemFont, 90)

    pauseLabel:setTextColor(50, 50, 50)

    pauseLabel:setReferencePoint( CenterReferencePoint )

    pauseLabel.x = halfW

    pauseLabel.y = 250

    

    – create a widget button

    restartBtn = widget.newButton{

        label="",

        labelColor = { default={255}, over={128} },

        fontSize = 0,

        defaultFile=“restart_btn.png”,

        overFile=“red_dot-over.png”,

        width=100, height=100,

        onRelease = onrestartBtnRelease

    }

    restartBtn:setReferencePoint( display.CenterReferencePoint )

    restartBtn.x = 200

    restartBtn.y = 475

    

    return true    – indicates successful touch

end

local function onrestartBtnRelease()

    

    – go to 1_player.lua scene

    storyboard.reloadScene( “1_player”, “fade”, 500 )

    

    return true    – indicates successful touch

end

[/lua]

the widget is changing to the “over” image, but the scene isn’t restarting.  I also tried it where it would go back to my main_menu.lua with the gotoScene, but that also didn’t work.

That’s because your button doesn’t yet know about the onrestartBtnRelease() function.  You need to either pre-declare it or place the function above the button creation code:

local function onpauseBtnPress() local myRoundedRect = display.newRoundedRect(134, 201, 500, 350, 12) myRoundedRect.strokeWidth = 8 myRoundedRect:setFillColor(214, 214, 214) myRoundedRect:setStrokeColor(111, 111, 111) local pauseLabel = display.newText("Paused", 0, 225, native.systemFont, 90) pauseLabel:setTextColor(50, 50, 50) pauseLabel:setReferencePoint( CenterReferencePoint ) pauseLabel.x = halfW pauseLabel.y = 250 local function onrestartBtnRelease() -- go to 1\_player.lua scene storyboard.reloadScene( "1\_player", "fade", 500 ) return true -- indicates successful touch end -- create a widget button restartBtn = widget.newButton{ label="", labelColor = { default={255}, over={128} }, fontSize = 0, defaultFile="restart\_btn.png", overFile="red\_dot-over.png", width=100, height=100, onRelease = onrestartBtnRelease } restartBtn:setReferencePoint( display.CenterReferencePoint ) restartBtn.x = 200 restartBtn.y = 475 return true -- indicates successful touch end

thanks

That’s because your button doesn’t yet know about the onrestartBtnRelease() function.  You need to either pre-declare it or place the function above the button creation code:

local function onpauseBtnPress() local myRoundedRect = display.newRoundedRect(134, 201, 500, 350, 12) myRoundedRect.strokeWidth = 8 myRoundedRect:setFillColor(214, 214, 214) myRoundedRect:setStrokeColor(111, 111, 111) local pauseLabel = display.newText("Paused", 0, 225, native.systemFont, 90) pauseLabel:setTextColor(50, 50, 50) pauseLabel:setReferencePoint( CenterReferencePoint ) pauseLabel.x = halfW pauseLabel.y = 250 local function onrestartBtnRelease() -- go to 1\_player.lua scene storyboard.reloadScene( "1\_player", "fade", 500 ) return true -- indicates successful touch end -- create a widget button restartBtn = widget.newButton{ label="", labelColor = { default={255}, over={128} }, fontSize = 0, defaultFile="restart\_btn.png", overFile="red\_dot-over.png", width=100, height=100, onRelease = onrestartBtnRelease } restartBtn:setReferencePoint( display.CenterReferencePoint ) restartBtn.x = 200 restartBtn.y = 475 return true -- indicates successful touch end

thanks