Forum

> > CS2D > Scripts > timer command
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch timer command

14 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt timer command

Zurak
User Off Offline

Zitieren
i cant figure out how to correctly use the timer command:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function betlock()
		betable = false
		msg("team bidding is now locked")
	end

	function startround(mode)
		betable = true
		timer(''..(1000)..','..betlock()..'')
		if mode == 50 then
			winner = 1
		elseif mode == 51 then
			winner = 2
		end
	end
error : attempt to concatenate a nil value
when i start the server the startround function doesn't even run and then when i restart the betlock function that is supposed to run 10 seconds later it runs instantly. am i doing something wrong?
1× editiert, zuletzt 15.07.12 22:27:58

alt Re: timer command

EngiN33R
Moderator Off Offline

Zitieren
The first argument to timer() is a number that is the time in milliseconds. The second argument is a string that is the function name, the third is the argument to that function, and the fourth is a number that is the number of repetitions.

user krabob hat geschrieben
1
timer(1000,betlock)

1
timer(1000,"betlock")

alt Re: timer command

Zurak
User Off Offline

Zitieren
thank you, but if there is a parameter for the function how would i be able to put it?
1× editiert, zuletzt 18.07.12 05:17:42

alt Re: timer command

Apache uwu
User Off Offline

Zitieren
Sorry then you will need to parse lua.

Example:

1
2
3
4
5
function addNumbers(number1,number2,number3)
	msg(number1+number2+number3)
end

timer(1000,"parse","lua addNumbers(2,3,10)")

That should message '15'.

alt Re: timer command

DC
Admin Off Offline

Zitieren
Well, here you go. Added some samples to the command reference.
See cs2d lua cmd timer

@user Zurak: Please note the following. It's a common mistake made by people who don't really understand all that ' and " and .. stuff:
• .. connects strings in Lua
• '' (two ' without anything between them) is an empty string without any content

This means that
1
EXPRESSION..''
or
1
EXPRESSION..''..EXPRESSION
or
1
''..EXPRESSION
NEVER EVER makes any sense. You attach an empty string this way. This means you change NOTHING by doing it. It's always 100% pointless in every possible situation. It only changes something if there is something between the two '!

alt Re: timer command

Zurak
User Off Offline

Zitieren
hmm...but is this possible with multiple parameters in the timer function?
1
2
3
4
5
6
7
function example(a,b)
	timer(1000,"parse","lua example2(a,b)",0)
end

function example2(a,b)
	some code
end

alt Re: timer command

DC
Admin Off Offline

Zitieren
This might actually work, yes. But you need to be careful with variables and quotes.

Line 2 should be:
1
timer(1000,"parse",'lua "example2('..a..','..b..')"',0)
So the timer will execute the Lua cs2d lua cmd parse function with parameter
1
lua "example2(valueOfa,valueOfb)"
And afterwards the CS2D command cs2d cmd lua will execute the code which is given as parameter in double quotes:
1
example2(valueOfa,valueOfb)

alt Re: timer command

Zurak
User Off Offline

Zitieren
Zitat
'lua "example2('..a..','..b..')"'

a bit of a mindfuck, but works :D, thanks.

alt Re: timer command

Infinite Rain
Reviewer Off Offline

Zitieren
DC Why didn't u made this function like: timer(time, function)?

It would be much easier:
timer(100, addhook('join', 'join_hook'))

alt Re: timer command

Apache uwu
User Off Offline

Zitieren
@user Infinite Rain: That would never work because you're calling the function when you send it, that would only return a value and from the c standpoint it can't hand anything.

On the other hand, if you use file cs2d Anonymous functions then your script could be:

timer(100, function()
			addhook('join', 'join_hook')
		end
)
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht