variable change true to false

I’ve been testing a test I made consisting of:
1 - Show a message at the beginning when the variable is false ball_contador. (at first).

2 - Show the message at the end when the variable changes to false.

The problem is that I can not change the variable to false ball_ruta function.

If it’s any help, I want to achieve is to run the message indicating when the ball end of the tour.

I do not know if I expressed myself well.

Thank you very much for your help in advance
Here’s the code:

[code]
local ball = display.newImageRect( “ball.png”, 50, 50 )
local ball_contador = false
ball.x = 240; ball.y = 188
local function ballruta()

ballrutaprimera = transition.to( ball, { time=7000, y=500})
local ball_contador = true

end
if (ball_contador == true) then
alerta = native.showAlert(“Mensaje”, “True”, {“OK”}, onClick)
else
alerta = native.showAlert(“Mensaje”, “False”, {“OK”}, onClick)
end

ballruta()

[code] [import]uid: 98258 topic_id: 31948 reply_id: 331948[/import]

Hi, just try removing the word *local* of your line 8 of the code above.

See:

[lua]local ball = display.newImageRect( “ball.png”, 50, 50 )
local ball_contador = false
ball.x = 240; ball.y = 188
local function ballruta()

ballrutaprimera = transition.to( ball, { time=7000, y=500})
ball_contador = true --<
end
if (ball_contador == true) then
alerta = native.showAlert(“Mensaje”, “True”, {“OK”}, onClick)
else
alerta = native.showAlert(“Mensaje”, “False”, {“OK”}, onClick)
end

ballruta()[/lua] [import]uid: 89165 topic_id: 31948 reply_id: 127392[/import]

thanks for your quick response.
I tested what you told me, but still do not see any messages when the ball reaches the end (true).
Any suggestions?
Thank you very much! [import]uid: 98258 topic_id: 31948 reply_id: 127393[/import]

Hi,

I do not know what you really want to do but if you want to see “the message” (alert) so you can test it below out and put it accordingly your own needs:

[lua]local ball = display.newCircle(200, 200, 69);
ball.x = 240;
ball.y = 188;

local ball_contador = false;

local function ballruta()
–ballrutaprimera = transition.to( ball, { time=7000, y=500});

ballrutaprimera = transition.to(ball, {time = 700, y = 500, onComplete = function()
if (ball_contador == true) then
alerta = native.showAlert(“Mensaje”, “True”, {“OK”}, onClick)
else
alerta = native.showAlert(“Mensaje”, “False”, {“OK”}, onClick)
end

ball_contador = true;

end})
end
ballruta()[/lua]

PS: Just change where I used [lua]display.newCircle()[/lua] for the image you want and just COPY and PASTE the code to see what it will do.
Cheers,
Rodrigo.
@RSCdev [import]uid: 89165 topic_id: 31948 reply_id: 127399[/import]

Thank you very much! I’ve gotten thank you.
What I do is run some code when the sprite reaches the bottom of the screen. What I like to do is that if the sprite was “removed” by some function, and nothing happened. Do not know what I mean. The message really is to try to work the mechanism and based on that and create the rest of the code I really need.
Do you think it’ll take well posed? or not?
Thanks for your help! [import]uid: 98258 topic_id: 31948 reply_id: 127425[/import]

Hi,

I really did not understand well what you meant but you can try posting some code when you want and so looking the code and your explanation about what you really want to do we can think together about the solution at all. :slight_smile:
Cheers,
Rodrigo.
@RSCdev [import]uid: 89165 topic_id: 31948 reply_id: 127499[/import]

Hi, just try removing the word *local* of your line 8 of the code above.

See:

[lua]local ball = display.newImageRect( “ball.png”, 50, 50 )
local ball_contador = false
ball.x = 240; ball.y = 188
local function ballruta()

ballrutaprimera = transition.to( ball, { time=7000, y=500})
ball_contador = true --<
end
if (ball_contador == true) then
alerta = native.showAlert(“Mensaje”, “True”, {“OK”}, onClick)
else
alerta = native.showAlert(“Mensaje”, “False”, {“OK”}, onClick)
end

ballruta()[/lua] [import]uid: 89165 topic_id: 31948 reply_id: 127392[/import]

thanks for your quick response.
I tested what you told me, but still do not see any messages when the ball reaches the end (true).
Any suggestions?
Thank you very much! [import]uid: 98258 topic_id: 31948 reply_id: 127393[/import]

Hi,

I do not know what you really want to do but if you want to see “the message” (alert) so you can test it below out and put it accordingly your own needs:

[lua]local ball = display.newCircle(200, 200, 69);
ball.x = 240;
ball.y = 188;

local ball_contador = false;

local function ballruta()
–ballrutaprimera = transition.to( ball, { time=7000, y=500});

ballrutaprimera = transition.to(ball, {time = 700, y = 500, onComplete = function()
if (ball_contador == true) then
alerta = native.showAlert(“Mensaje”, “True”, {“OK”}, onClick)
else
alerta = native.showAlert(“Mensaje”, “False”, {“OK”}, onClick)
end

ball_contador = true;

end})
end
ballruta()[/lua]

PS: Just change where I used [lua]display.newCircle()[/lua] for the image you want and just COPY and PASTE the code to see what it will do.
Cheers,
Rodrigo.
@RSCdev [import]uid: 89165 topic_id: 31948 reply_id: 127399[/import]

Thank you very much! I’ve gotten thank you.
What I do is run some code when the sprite reaches the bottom of the screen. What I like to do is that if the sprite was “removed” by some function, and nothing happened. Do not know what I mean. The message really is to try to work the mechanism and based on that and create the rest of the code I really need.
Do you think it’ll take well posed? or not?
Thanks for your help! [import]uid: 98258 topic_id: 31948 reply_id: 127425[/import]

Hi,

I really did not understand well what you meant but you can try posting some code when you want and so looking the code and your explanation about what you really want to do we can think together about the solution at all. :slight_smile:
Cheers,
Rodrigo.
@RSCdev [import]uid: 89165 topic_id: 31948 reply_id: 127499[/import]