Omnimaga

Calculator Community => TI Calculators => Lua => Topic started by: rohanlukose on June 01, 2012, 01:49:44 pm

Title: Delay function
Post by: rohanlukose on June 01, 2012, 01:49:44 pm
Does any one know about delay/sleep function that can be used with nspire lua as on.clock() wont work ???
Title: Re: Delay function
Post by: aeTIos on June 01, 2012, 01:54:18 pm
Welcome on the forums! You should introduce yourself (http://www.omnimaga.org/index.php?board=10.0)!
There are plenty experienced Lua programmers out here, so I'm sure they will figure it out for you :D
Title: Re: Delay function
Post by: Nick on June 01, 2012, 02:54:55 pm
on.clock() ? never heard of it รถ i program in lua :) well, you can use the timer to make your own delay function, but there's no native one..

timer.getMilliSecCounter() returns the nr of milliseconds since the calc rebooted, that way you can make your own
Title: Re: Delay function
Post by: jwalker on June 01, 2012, 03:14:41 pm
you could use on.tick
Title: Re: Delay function
Post by: Adriweb on June 01, 2012, 05:34:30 pm
There has been some topics already about this kind of things.

Generally (with all due respect), you don't really have to really "pause" the script flow directly, but maybe you just mess with [lua]on.timer[/lua] (not 'on.clock', nor 'on.tick'), which is called every tick, whose period is define by [lua]timer.start[/lua]
Title: Re: Delay function
Post by: Juju on June 01, 2012, 07:04:16 pm
Yeah, you'll want to start a timer or save the current time, then check if your desired number of time has been elapsed.
Title: Re: Delay function
Post by: Jim Bauwens on June 02, 2012, 05:44:25 am
One important difference with the Lua API (and also with the Love API) is that it is event based.
Tight while loops are not recommended. This might be confusing in the beginning, but you will appreciate it in the end ;)

So you will need to use the timer system. [lua]timer.start[/lua](x) will make that the on.timer event will fire every x seconds.
You will have to define on.timer so that it does the changes you want and then invalidates the screen so that the screen will be redrawn.