Changing a timer's delay on the fly?

Hi all,

Is there any way to change the delay of a running timer on the fly? I’d like to change the speed at which a timer spawns objects depending on a few conditions, and once those conditions are met, I’d like the timer to continue running, but to just have a different delay.

Thanks!
Logan [import]uid: 44896 topic_id: 18002 reply_id: 318002[/import]

Unfortunately no, not at this time. You’d have to cancel and restart it with a new delay parameter. [import]uid: 52491 topic_id: 18002 reply_id: 68881[/import]

@Peach
Correct me if I am wrong but isn’t this possible?
[lua]local myTimer = timer.performWithDelay(1000,myFunction,0)
myTimer._delay = 2000[/lua] [import]uid: 64174 topic_id: 18002 reply_id: 71166[/import]

Satheesh! Aweseome!

You are correct this does indeed work.

In the past this discussion came up (some time ago now, before I was staff) and it seemed only possible with a workaround; nothing on the fly.

Do you mind if I ask where you found that solution? (It may be something I’ve missed but I don’t think it’s anywhere obvious in our docs - and if not, it should be.)

Thanks!
Peach :slight_smile: [import]uid: 52491 topic_id: 18002 reply_id: 71194[/import]

well… I was wondering how to pause all my timers and transitions and found this when messing around with the timer and transition classes. Also found a whole lot of other useful tables like timer._runlist, transition._activeTweens, etc. :slight_smile: [import]uid: 64174 topic_id: 18002 reply_id: 71206[/import]

Oh, wow, Satheesh. The tables you mentioned sound super useful, and I could definitely use timer._runlist and transition._activeTweens (assuming they return all active timers/transitions, maybe?)

So far, you’ve mentioned:

timer._delay
timer._runlist
transition._activeTweens

What other ones are there? And where did you find them? If you remember, I’d love to learn about it.

And, Peach, it would be so nice if they are added to API section somehow (with a quick explanation of what each of them do). I’d look for them there first:

http://developer.anscamobile.com/reference/index/timer
http://developer.anscamobile.com/content/transitions

Naomi [import]uid: 67217 topic_id: 18002 reply_id: 71210[/import]

I did not “FIND” them anywhere… just iterated through the timer and transition tables

[lua]for k,v in pairs(timer)
print(k,v)
end[/lua]

You can do the same for literally every Corona oriented table and get several useful variables and functions.

:slight_smile: [import]uid: 64174 topic_id: 18002 reply_id: 71214[/import]

This. is. awesome! Thanks so much! Wow. [import]uid: 44896 topic_id: 18002 reply_id: 71217[/import]

Glad to help! :slight_smile: [import]uid: 64174 topic_id: 18002 reply_id: 71219[/import]

Wow, okay, that sounds great. When I get a chance, I’ll definitely investigate more.

Thanks, Satheesh!

Naomi [import]uid: 67217 topic_id: 18002 reply_id: 71225[/import]

Hey guys,

I’ve just checked with the team about this and apparently this is not recommended code :frowning:

“The recommended way is to cancel the timer and call performwithdelay with the new desired delay.”

This is because future changes could break this method.

Sorry - still a very clever find, though :slight_smile:

Peach. [import]uid: 52491 topic_id: 18002 reply_id: 71229[/import]

Ah shoot! Still never mind! :smiley:
What about the other tables though? the ones like timer._runlist and transition._activetweens…
Can I use them? Is that “Recommended”? :wink: [import]uid: 64174 topic_id: 18002 reply_id: 71243[/import]

Nothing undocumented is “recommended”, I’m afraid :frowning:

I still think it was a very clever find, though :slight_smile:

Peach [import]uid: 52491 topic_id: 18002 reply_id: 71251[/import]

Thanks for that! :slight_smile:
Anyway, I’m gonna stick my neck out and use these anyway… To hell with “recommendations” :smiley: :smiley:

Thanks for the info though :slight_smile: [import]uid: 64174 topic_id: 18002 reply_id: 71255[/import]