objec:pause() and transition.cancel not working properly (for me)

Hi everyone!

I’m having a problem with my pause function

[code]function GameHelper:pauseGame(npcs)

cameraLocked = true
update = false

if npcs then
for i = 1, npcs.numChildren do
npcs[i]:pause( )
if npcs[i].transition then
transition.cancel ( npcs[i].transition )
end
end
end
end
[/code]

It works, but not always. I often end up having one or a couple of npcs not pausing their animation or canceling their transition, this goes for when I only have one in total as well, sometimes it works great others it just don’t.

Anyone got an idea of what might be causing this behavior? [import]uid: 129450 topic_id: 28560 reply_id: 328560[/import]

Info583 ,

what happens if you change your line 8 for:

[lua]function GameHelper:pauseGame(npcs)

cameraLocked = true
update = false

if npcs then
for i = 1, npcs.numChildren do
npcs[i]:pause( npcs[i] ) --< if npcs[i].transition then
transition.cancel ( npcs[i].transition )
end
end
end
end[/lua]

Just a shot.
Let me know.

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 28560 reply_id: 115119[/import]

Thanks for the quick reply Rodrigo!

I tried both your suggestions but the problem still persists. [import]uid: 129450 topic_id: 28560 reply_id: 115122[/import]

No problem!

Try something like this:
What you would try to do is go through your npcs table *backward*.

[lua]for i=#npcs, 1, -1 do
–stuff
end[/lua]

That will eliminate any out-of-bounds index issues or skips on your table.
[import]uid: 89165 topic_id: 28560 reply_id: 115123[/import]

I tried this as well, although I didn’t have any problems with it being out of index since I don’t remove anything from the display group at this point. And to little surprise it didn’t help, good suggestion though!

I just can’t figure out why it doesn’t always work, I create all my entities in the same manner and have them in the same group, and yet this happens. I have also counted and compared the number of entities in the game with the .numChildren of the display group and they always add up (if they didn’t, it would show during gameplay as the entity in question would not get update calls).

All this to make a working pause function. Doesn’t Corona have a var that regulates the speed of the whole app? I.e a global deltaTime var, which if set to 0 stops all time based movement and functions in the app. [import]uid: 129450 topic_id: 28560 reply_id: 115298[/import]

Ops,

Sorry not being helpful at all.

Maybe someone else will get it with you.

@Peach is a good person to look into it. Ask her and am sure she will bring something nice up.
Rodrigo. [import]uid: 89165 topic_id: 28560 reply_id: 115300[/import]

No worries Rodrigo,

even though we didn’t reach a solution you gave solid advice as always :slight_smile:

Will do! Thanks again. [import]uid: 129450 topic_id: 28560 reply_id: 115759[/import]

@info583,

I appreciate your words. Thank you too!

BTW, ping @Peach if you want to because I think she would help you to sove this issue. She is nice and smart! :wink:

Excuse me for anything,

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 28560 reply_id: 115844[/import]