function that pause a loop for x amount of time

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
my psprecious
Posts: 24
Joined: Fri Feb 17, 2006 5:08 am

function that pause a loop for x amount of time

Post by my psprecious »

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
yossistarz2
Posts: 21
Joined: Mon Apr 10, 2006 5:26 am
Contact:

Post by yossistarz2 »

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.
my psprecious
Posts: 24
Joined: Fri Feb 17, 2006 5:08 am

Post by my psprecious »

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
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Is System.sleep(milliseconds) what do you need?
yossistarz2
Posts: 21
Joined: Mon Apr 10, 2006 5:26 am
Contact:

Post by yossistarz2 »

try this on Millisecond timer base.

Code: Select all

function sleep&#40;MT&#41;
	t =  Timer.new&#40;0&#41;
	t&#58;start&#40;&#41;
	while &#40;t&#58;time&#40;&#41; < MT&#41; do

	end
	t&#58;stop&#40;&#41;
end
my psprecious
Posts: 24
Joined: Fri Feb 17, 2006 5:08 am

Post by my psprecious »

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
yossistarz2
Posts: 21
Joined: Mon Apr 10, 2006 5:26 am
Contact:

Post by yossistarz2 »

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.
my psprecious
Posts: 24
Joined: Fri Feb 17, 2006 5:08 am

Post by my psprecious »

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
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Post by DiabloTerrorGF »

System.sleep(milliseconds)

Should work...
yossistarz2
Posts: 21
Joined: Mon Apr 10, 2006 5:26 am
Contact:

Post by yossistarz2 »

I don't know what about that but check this as a proof:
(stops for 1 second)

Code: Select all


function sleep&#40;MT&#41;
   t =  Timer.new&#40;0&#41;
   t&#58;start&#40;&#41;
   while &#40;t&#58;time&#40;&#41; < MT&#41; do

   end
   t&#58;stop&#40;&#41;
end

screen&#58;clear&#40;Color.new&#40;255,0,0&#41;&#41;
screen&#58;flip&#40;&#41;
screen&#58;flip&#40;&#41;

sleep&#40;1000&#41;

screen&#58;clear&#40;Color.new&#40;255,255,0&#41;&#41;
screen&#58;flip&#40;&#41;
screen&#58;flip&#40;&#41;

sleep&#40;1000&#41;

screen&#58;clear&#40;Color.new&#40;255,0,255&#41;&#41;
screen&#58;flip&#40;&#41;
screen&#58;flip&#40;&#41;

sleep&#40;1000&#41;

screen&#58;clear&#40;Color.new&#40;0,0,255&#41;&#41;
screen&#58;flip&#40;&#41;
screen&#58;flip&#40;&#41;
sleep&#40;1000&#41;

KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

What is wrong with System.sleep(ms)? It should do the job.
Last edited by KawaGeo on Wed Apr 19, 2006 11:23 am, edited 1 time in total.
Geo Massar
Retired Engineer
yossistarz2
Posts: 21
Joined: Mon Apr 10, 2006 5:26 am
Contact:

Post by yossistarz2 »

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).
Post Reply