Forum

> > CS2D > Scripts > timer command
Forums overviewCS2D overview Scripts overviewLog in to reply

English timer command

14 replies
To the start Previous 1 Next To the start

old timer command

Zurak
User Off Offline

Quote
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?
edited 1×, last 15.07.12 10:27:58 pm

old Re: timer command

EngiN33R
Moderator Off Offline

Quote
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 has written
1
timer(1000,betlock)

1
timer(1000,"betlock")

old Re: timer command

Zurak
User Off Offline

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

old Re: timer command

Apache uwu
User Off Offline

Quote
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'.

old Re: timer command

DC
Admin Off Offline

Quote
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 '!

old Re: timer command

Zurak
User Off Offline

Quote
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

old Re: timer command

DC
Admin Off Offline

Quote
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)

old Re: timer command

Zurak
User Off Offline

Quote
Quote
'lua "example2('..a..','..b..')"'

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

old Re: timer command

Infinite Rain
Reviewer Off Offline

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

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

old Re: timer command

Apache uwu
User Off Offline

Quote
@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
)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview