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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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) 

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

Please let me know :)

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

print("good") and nothing happen what could be the problem?

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--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 

@peach I'm just wondering if your still helping with the problem I got sorry for being inpatient

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;

1
2
3
4
5
6
7
8
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

@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 :)

No worries - happy to be able to help!

Peach :)

views:1854 update:2012/1/9 8:53:30
corona forums © 2003-2011