Forum

> > CS2D > Scripts > how to creat a delay.
Forums overviewCS2D overview Scripts overviewLog in to reply

English how to creat a delay.

9 replies
To the start Previous 1 Next To the start

old how to creat a delay.

if
User Off Offline

Quote
I'm making a football script,how to make a delay between goal and a new ball?

old Re: how to creat a delay.

DannyDeth
User Off Offline

Quote
use os.clock like this:
1
2
3
4
5
6
delay = 3 -- delay time in seconds
start = os.clock()
while (os.clock() ~= start+delay) do
	-- leave this empty, or comment like me. :P
end
add_newball_function()
os.clock returns the time that the program has been running for in seconds ( correct me if I'm wrong here ). So by adding the delay to start and finding os.clock each loop, we can effectively create a delay.

old Re: how to creat a delay.

Nem
User Off Offline

Quote
I dont sure about CS2D, but if this was CC, you must make timer. But I am sure its kinda right.

old Re: how to creat a delay.

DannyDeth
User Off Offline

Quote
To trigger the delay I would reccomend putting it like this:
1
2
3
4
5
6
7
8
function delay_to_new_ball()
	delay = 3 -- delay time in seconds
	start = os.clock()
	while (os.clock() ~= start+delay) do
		-- leave this empty, or comment like me. :P
	end
	add_newball_function()
end
where it says add_newball_function(), replace with your own code/function.

old Re: how to creat a delay.

Yasday
User Off Offline

Quote
On linux os.clock isn't always returning the time the programm was running. You should use os.time and os.difftime instead.

old Re: how to creat a delay.

DC
Admin Off Offline

Quote
what DannyDeth said is very dangerous! do NOT do this! reason: it will pause the whole game which leads to lags and high pings! moreover it will lead to maximum CPU load because CS2D will try to execute this Lua loop as fast as possible.

CS2D has built-in timers to make your life easier:
see cs2d lua cmd timer - use them instead.

old Re: how to creat a delay.

DannyDeth
User Off Offline

Quote
user DC has written
What DannyDeth said is very dangerous!

you are not the first person to say that about my code before. But, yes, DC is very right. Didn't really think about the fact that it will pause EVERYTHING in CS2D.. lolz. It's like the ultimate malfunction.

old Re: how to creat a delay.

if
User Off Offline

Quote
I just used parse trigger a delay in the map,
That script was too complicated for me.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview