Author Topic: Delay function  (Read 2938 times)

0 Members and 1 Guest are viewing this topic.

Offline rohanlukose

  • LV0 Newcomer (Next: 5)
  • Posts: 1
  • Rating: +0/-0
    • View Profile
Delay function
« 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 ???

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Delay function
« Reply #1 on: June 01, 2012, 01:54:18 pm »
Welcome on the forums! You should introduce yourself!
There are plenty experienced Lua programmers out here, so I'm sure they will figure it out for you :D
« Last Edit: June 01, 2012, 01:54:33 pm by aeTIos »
I'm not a nerd but I pretend:

Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: Delay function
« Reply #2 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

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: Delay function
« Reply #3 on: June 01, 2012, 03:14:41 pm »
you could use on.tick
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Delay function
« Reply #4 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]
« Last Edit: June 02, 2012, 06:28:22 am by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: Delay function
« Reply #5 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.
« Last Edit: June 01, 2012, 07:04:59 pm by Juju »

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Delay function
« Reply #6 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.
« Last Edit: June 02, 2012, 05:45:04 am by jimbauwens »