Going back and forth on 2 pages.

Hi, I’m new to both coding and solar2d.

From what I’m seeing, the script should work with the appropriate “functions” of going to another page. But what’s happening is, when I press the “Get Started” button, it redirects me to the next page. On page 2, I can press the back button to go back to the main page or recent page, the button works and takes me back to the previous page but there, I can no longer press the “Get Started” button.

–main lua–

-- Function to handle button tap

local function handleButtonTap(event)

    if (event.phase == "ended") then

        composer.gotoScene("page2")

    end

end

-- Create a button

local myButton = widget.newButton({

    label = "Get Started",

    onEvent = handleButtonTap,

    emboss = false,

    shape = "rectangle",

    width = 200,

    height = 75,

    cornerRadius = 2,

    fillColor = { default={0,0,0}, over={0,0,0} },

    labelColor  = { default={1,1,1}, over={1,1,1} },

    fontSize  = 25,

    font = "Arial Black"

})

-- Position the button

myButton.x = display.contentCenterX

myButton.y = 400

-- Add the button to the display group

local sceneGroup = display.newGroup()

sceneGroup:insert(myButton)

–2nd page–


--back button------
local function handleButtonTap(event)
    if (event.phase == "ended") then
        composer.gotoScene("main")
    end
end


local myButton = widget.newButton({
    onEvent = handleButtonTap,
    emboss = false,
    defaultFile = "images/shapes/back.png",
    width = 20,
    height = 20,
    cornerRadius = 2,
})
-- Position the button
myButton.x = 50
myButton.y = 565

-- Add the button to the display group
local sceneGroup = display.newGroup()
sceneGroup:insert(myButton)

Try adding composer.removeScene to your button events:

local function handleButtonTap(event)
    if (event.phase == "ended") then
        composer.removeScene("page2")
        composer.gotoScene("page2")
    end
    return true
end
local function handleButtonTap(event)
    if (event.phase == "ended") then
        composer.removeScene("main")
        composer.gotoScene("main")
    end
    return true
end

(I also threw return true in there because prevents the touch from propagating to objects under the button. Not important in this instance, but a good habit to get into.)