Problem on changing scene with Native Alert

Hi yall I’m having problems with the Native Alert when trying to change scene ok the problem is when the ball collides with a box the Native Alert shows just how I wanted. But when I click on the button the scene does not change is like if my click was cancelled here is the code

[code]local function onClicks(event)
if event.action == “clicked” then
elseif event.index == 1 then
director:changeScene (“menu”, “flip”)
elseif event.index == 2 then
director:changeScene (“menu”)
end
end
– Display Alert

function onCollision5( event )
if event.phase == “began” and event.other.name == “bg22” then
physics.pause()
local alerts = native.showAlert(“Congratulations”, “Level 1”, {“Main Menu”, “Redo”}, onClicks)
end
end
ball.preCollision = onLocalPreCollision
ball:addEventListener( “collision”, onCollision5) [/code]

Yeah as I say it again when I click on Main menu or Redo no scene changes the buttons acts like if they been cancelled

Help is appreciated [import]uid: 17058 topic_id: 20043 reply_id: 320043[/import]

Have you tried a print statement to make sure that the function is being called correctly?

Please let me know :slight_smile: [import]uid: 52491 topic_id: 20043 reply_id: 78240[/import]

@peach yeah I did a print function on line 16 saying

print(“good”) and nothing happen what could be the problem? [import]uid: 17058 topic_id: 20043 reply_id: 78245[/import]

If a print on line 16 didn’t work I wouldn’t think the alert would show at all because the function wouldn’t be getting called.

Maybe upload a sample or provide plug and play code?

I was going to suggest a print on lines 4 and 6 to show the button press was registering but if a print isn’t happening on line 16 I don’t know that it would work.

What happens if you print on line 14?

Peach [import]uid: 52491 topic_id: 20043 reply_id: 78286[/import]

@peach ok here the play code this should what this does is when you click the redo button nothings changes

[code]
–main.lua

display.setStatusBar (display.HiddenStatusBar)
–> Hides the status bar

local director = require (“director”)
–> Imports director

local mainGroup = display.newGroup()
–> Creates a main group

local function main()
–> Adds main function

mainGroup:insert(director.directorView)
–> Adds the group from director

director:changeScene(“menu”)
–> Change the scene, no effects

return true
end

main()

–menu.lua

module(…, package.seeall)

function new()
local localGroup = display.newGroup()

local physics = require(“physics”)
physics.start()

local ball = display.newCircle(10,10,10,10)
ball.x = 10
ball.y = 240
physics.addBody(ball, { density = 1.5, friction = 0.0, bounce = 0.1 })

local paddle = display.newRect(0,500,1000,20)
paddle.y = 480
paddle.x = 100
physics.addBody(paddle, “static” )

local paddle2 = display.newRect(0,500,1000,20)
paddle2.y = 700
paddle2.x = 350
paddle2.rotation = 34
physics.addBody(paddle2, “static” )

local paddle3 = display.newRect(0,500,1000,20)
paddle3.y = 160
paddle3.x = 240
paddle3.rotation = 90
physics.addBody(paddle3, “static” )
paddle3.name = “paddle3”

local function onClicks(event)
if event.action == “clicked” then
elseif event.index == 1 then
director:changeScene (“menu”, “flip”)
elseif event.index == 2 then
director:changeScene (“menu”)
end
end
– Display Alert

function onCollision( event )
if event.phase == “began” and event.other.name == “paddle3” then
physics.pause()
local alerts = native.showAlert(“Congratulations”, “Level 1”, {“Main Menu”, “Redo”}, onClicks)
end
end
ball.preCollision = onLocalPreCollision
ball:addEventListener( “collision”, onCollision)

return localGroup
end [/code]

Also thanks for help :slight_smile: [import]uid: 17058 topic_id: 20043 reply_id: 78330[/import]

@peach I’m just wondering if your still helping with the problem I got sorry for being inpatient [import]uid: 17058 topic_id: 20043 reply_id: 78418[/import]

Hello sebitttas,

I am indeed - you just have to keep in mind I help lots of people and we are also located in different time zones.

Now - I caught the problem, which I should have spotted earlier this was your onClicks function;

[lua]local function onClicks(event)
if event.action == “clicked” then
elseif event.index == 1 then
director:changeScene (“menu”, “flip”)
elseif event.index == 2 then
director:changeScene (“menu”)
end
end[/lua]

Change it to this;

[lua]local function onClicks(event)
if event.action == “clicked” then
if event.index == 1 then
director:changeScene (“menu”, “flip”)
elseif event.index == 2 then
director:changeScene (“menu”)
end
end
end[/lua]

Now, the other problem is you’re trying to load the scene you are currently in, so a quick work around (just to show you this is working) is to make a new file, which we’ll call goMenu.lua;

[lua]module(…, package.seeall)

function new()
local localGroup = display.newGroup()

local function reloadMenu ()
director:changeScene(“menu”)
end
timer.performWithDelay(100, reloadMenu, 1)


return localGroup
end[/lua]

Then in onClicks, change “menu” to “goMenu”.

Also make sure you are putting objects in the localGroup for director.

Peach :slight_smile: [import]uid: 52491 topic_id: 20043 reply_id: 78442[/import]

@peach thanks so much when I saw the difference of my mistake it took me a while to figure it out. Yeah I know about the time zone we are like more than 12 hours apart. Also yeah I know your busy I’ll be patient next time and let you take your time and do your job helping people and other things.

So thanks a lot and have a nice day :slight_smile: [import]uid: 17058 topic_id: 20043 reply_id: 78457[/import]

No worries - happy to be able to help!

Peach :slight_smile: [import]uid: 52491 topic_id: 20043 reply_id: 78473[/import]