Forum

> > CS2D > Scripts > how to creat a delay.
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch how to creat a delay.

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt how to creat a delay.

if
User Off Offline

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

alt Re: how to creat a delay.

DannyDeth
User Off Offline

Zitieren
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.

alt Re: how to creat a delay.

Nem
User Off Offline

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

alt Re: how to creat a delay.

DannyDeth
User Off Offline

Zitieren
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.

alt Re: how to creat a delay.

Yasday
User Off Offline

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

alt Re: how to creat a delay.

DC
Admin Off Offline

Zitieren
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.

alt Re: how to creat a delay.

DannyDeth
User Off Offline

Zitieren
user DC hat geschrieben
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.

alt Re: how to creat a delay.

if
User Off Offline

Zitieren
I just used parse trigger a delay in the map,
That script was too complicated for me.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht