In my game if the ball falls in the basket, an alert have to be displayed… but it displays more alerts, because the ball collides more times. How to display an alert only at the FIRST collision? [import]uid: 27760 topic_id: 30361 reply_id: 330361[/import]
Try this in the function that’s called after the ball hits the basket.
[lua]local ballbasketCount = 0
ballbasketCount = ballbasketCount + 1
if ballbasketCount == 1 then
else
end[/lua]
You can have your gameover/exit/restart scene reset ballbasketCount to 0 if needed.
[import]uid: 62706 topic_id: 30361 reply_id: 121621[/import]
I’ve tried something like this, but it doesn’t run…
[code]
– Alert
local function onComplete( event )
if “clicked” == event.action then
local i = event.index
if 1 == i then
director:changeScene(“level10”)
end
end
end
–collision
local function hitGround (event)
local ballbasketCount = 0
ballbasketCount = ballbasketCount + 1
if ballbasketCount == 1 then
else
–Alert
local alert = native.showAlert( “Congratulations!!!”, “Go to the next level”, { “Next Level” }, onComplete )
end
end
end
flag:addEventListener(“collision”, hitGround)
[/code] [import]uid: 27760 topic_id: 30361 reply_id: 121658[/import]
You have your alert outside of the if statement in the code above, move line 25 to line 22 and try again. [import]uid: 62706 topic_id: 30361 reply_id: 121660[/import]
It doesn’t run even if I try this… could you post a code made by you please?
thanks in advance [import]uid: 27760 topic_id: 30361 reply_id: 121663[/import]
Cant write/test code for a few hours until I get home - Try this though
[lua]-- Alert
local function onComplete( event )
if “clicked” == event.action then
local i = event.index
if 1 == i then
director:changeScene(“level10”)
end
end
end
–collision
local function hitGround (event)
local ballbasketCount = 0
ballbasketCount = ballbasketCount + 1
if ballbasketCount == 1 then
native.showAlert( “Congratulations!!!”, “Go to the next level”, { “Next Level” }, onComplete )
else
end
end
flag:addEventListener(“collision”, hitGround)[/lua] [import]uid: 62706 topic_id: 30361 reply_id: 121664[/import]
Try this in the function that’s called after the ball hits the basket.
[lua]local ballbasketCount = 0
ballbasketCount = ballbasketCount + 1
if ballbasketCount == 1 then
else
end[/lua]
You can have your gameover/exit/restart scene reset ballbasketCount to 0 if needed.
[import]uid: 62706 topic_id: 30361 reply_id: 121621[/import]
I’ve tried something like this, but it doesn’t run…
[code]
– Alert
local function onComplete( event )
if “clicked” == event.action then
local i = event.index
if 1 == i then
director:changeScene(“level10”)
end
end
end
–collision
local function hitGround (event)
local ballbasketCount = 0
ballbasketCount = ballbasketCount + 1
if ballbasketCount == 1 then
else
–Alert
local alert = native.showAlert( “Congratulations!!!”, “Go to the next level”, { “Next Level” }, onComplete )
end
end
end
flag:addEventListener(“collision”, hitGround)
[/code] [import]uid: 27760 topic_id: 30361 reply_id: 121658[/import]
You have your alert outside of the if statement in the code above, move line 25 to line 22 and try again. [import]uid: 62706 topic_id: 30361 reply_id: 121660[/import]
It doesn’t run even if I try this… could you post a code made by you please?
thanks in advance [import]uid: 27760 topic_id: 30361 reply_id: 121663[/import]
Cant write/test code for a few hours until I get home - Try this though
[lua]-- Alert
local function onComplete( event )
if “clicked” == event.action then
local i = event.index
if 1 == i then
director:changeScene(“level10”)
end
end
end
–collision
local function hitGround (event)
local ballbasketCount = 0
ballbasketCount = ballbasketCount + 1
if ballbasketCount == 1 then
native.showAlert( “Congratulations!!!”, “Go to the next level”, { “Next Level” }, onComplete )
else
end
end
flag:addEventListener(“collision”, hitGround)[/lua] [import]uid: 62706 topic_id: 30361 reply_id: 121664[/import]