| View previous topic :: View next topic |
| Author |
Message |
my psprecious
Joined: 17 Feb 2006 Posts: 24
|
Posted: Tue Apr 18, 2006 10:35 am Post subject: function that pause a loop for x amount of time |
|
|
Ok, I'm working on an animation in lua for the intro of my game
and I'm trying to do a pause in the loop as a function
so I can use it anywhere I need a pause and just change the value of my pause like something like this
function sleep(wait)
if i <= to wait do
i = i + 1
something missing here to pause it I was suggested waitvblank() but I don't think it exist
end
and everytime I call it I would have something like this sleep(30), 30 been the amount I need for that pause at that momment
could someone help I'm pretty lost |
|
| Back to top |
|
 |
yossistarz2
Joined: 10 Apr 2006 Posts: 21
|
Posted: Tue Apr 18, 2006 11:48 am Post subject: |
|
|
The function you are asking for is this I hope...
function sleep(Wait)
i = 0
while i <= Wait do
i = i + 1
end
end
But you will need a very large amount of Wait number in order to see a difference. |
|
| Back to top |
|
 |
my psprecious
Joined: 17 Feb 2006 Posts: 24
|
Posted: Tue Apr 18, 2006 12:06 pm Post subject: |
|
|
BIG thanx
this is gona be useful
EDIT
Doesn't work, I tried with 300000 and finally saw a difference, but what it did is not pause my loop since the loop continues, what it does it slows the loop |
|
| Back to top |
|
 |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Tue Apr 18, 2006 5:55 pm Post subject: |
|
|
| Is System.sleep(milliseconds) what do you need? |
|
| Back to top |
|
 |
yossistarz2
Joined: 10 Apr 2006 Posts: 21
|
Posted: Tue Apr 18, 2006 5:56 pm Post subject: |
|
|
try this on Millisecond timer base.
| Code: |
function sleep(MT)
t = Timer.new(0)
t:start()
while (t:time() < MT) do
end
t:stop()
end |
|
|
| Back to top |
|
 |
my psprecious
Joined: 17 Feb 2006 Posts: 24
|
Posted: Wed Apr 19, 2006 2:01 am Post subject: |
|
|
Well what it does is pause my script on start not when I call the function
When I think that all this was to simplify my life hehehe |
|
| Back to top |
|
 |
yossistarz2
Joined: 10 Apr 2006 Posts: 21
|
Posted: Wed Apr 19, 2006 2:42 am Post subject: |
|
|
I am not shore what you are talking about.
When you call it it pause the program to X milliseconds and then continue.
Pause means dead time nothing is doing for x milliseconds.
If i hope i understands what you want. |
|
| Back to top |
|
 |
my psprecious
Joined: 17 Feb 2006 Posts: 24
|
Posted: Wed Apr 19, 2006 8:41 am Post subject: |
|
|
yes exactly do nothing for x amount of time
I'm able to do it another way but it would have been useful to have a function pause(time) that I can call when I need a x amount of pause |
|
| Back to top |
|
 |
DiabloTerrorGF
Joined: 15 Jul 2005 Posts: 64
|
Posted: Wed Apr 19, 2006 10:28 am Post subject: |
|
|
System.sleep(milliseconds)
Should work... |
|
| Back to top |
|
 |
yossistarz2
Joined: 10 Apr 2006 Posts: 21
|
Posted: Wed Apr 19, 2006 10:38 am Post subject: |
|
|
I don't know what about that but check this as a proof:
(stops for 1 second)
| Code: |
function sleep(MT)
t = Timer.new(0)
t:start()
while (t:time() < MT) do
end
t:stop()
end
screen:clear(Color.new(255,0,0))
screen:flip()
screen:flip()
sleep(1000)
screen:clear(Color.new(255,255,0))
screen:flip()
screen:flip()
sleep(1000)
screen:clear(Color.new(255,0,255))
screen:flip()
screen:flip()
sleep(1000)
screen:clear(Color.new(0,0,255))
screen:flip()
screen:flip()
sleep(1000)
|
|
|
| Back to top |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Wed Apr 19, 2006 11:13 am Post subject: |
|
|
What is wrong with System.sleep(ms)? It should do the job. _________________ Geo Massar
Retired Engineer
Last edited by KawaGeo on Wed Apr 19, 2006 11:23 am; edited 1 time in total |
|
| Back to top |
|
 |
yossistarz2
Joined: 10 Apr 2006 Posts: 21
|
Posted: Wed Apr 19, 2006 11:18 am Post subject: |
|
|
Maybe, But it jest for the question.
Your answer should solve it but it is good thing to now how to implement things in more then one way (it never harms). |
|
| Back to top |
|
 |
|