Forum

> > CS2D > Scripts > Timer error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Timer error

7 replies
To the start Previous 1 Next To the start

old Timer error

Infinite Rain
Reviewer Off Offline

Quote
Hey guys!
Could someone help me with timer function?
1
timer(20, 'open_menu(id)')

It returns nil error in no line
Please help me

Edit:
If you need full hook its here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function clientdata_hook(id, mode, data1, data2)
	local x = data1
	local y = data2
	if actived[id] == 1 then
		if posInArea(x, y, closebutton[1], closebutton[2], closebutton[3], closebutton[4]) then
			freeimage(imgid[id])
			parse('sv_sound2 '.. id ..' "wpn_select.wav"')
			actived[id] = 0
		else
			for n, w in ipairs(pos) do
				if posInArea(x, y, w[1], w[2], w[3], w[4]) then
					lastselect[id] = n 
					freeimage(imgid[id])
					parse('sv_sound2 '.. id ..' "wpn_select.wav"')
					actived[id] = 0
					timer(20, 'open_menu(id)')
					break
				end
			end
		end
	end
end

old Re: Timer error

DC
Admin Off Offline

Quote
you have to pass the function NAME only, not the function pattern with parameters.

change 'open_menu(id)' to 'open_menu'

(you can add a third parameters with a value for the id function parameter if you want to)
edited 1×, last 02.08.11 06:34:19 pm

old Re: Timer error

DC
Admin Off Offline

Quote
see my edit. and you should really read the command reference.
cs2d lua cmd timer

note that only one parameter is possible for functions called with a timer.

old Re: Timer error

Bowlinghead
User Off Offline

Quote
I dont want to make a extra thread:
How can I use timer?
I want to make a spawn script and an item has to be after 1 minute strip.
Can anyone help?
1
2
3
4
5
6
7
8
9
10
11
12
addhook("spawn","spawnlol")
function spawnlol(id)
	if classes[id]==1 then
		return "45";
		timer(1200, parse("strip "..id.." 45")
	end
end
--[[ Error: 
LUA ERROR: sys/lua/uav_mode.lua:65: 'end' expected (to close 'if' at line 63) near 'timer'
Line:
timer(1200, parse("strip "..id.." 71")
]]

Is it possible to do that?

old Re: Timer error

Apache uwu
User Off Offline

Quote
I lol'd @ semicolon, you can add it in but it's not needed.

Also timer can only take function names in quotes. Then you can add params...

ex.

untested:

1
2
param="strip "..id.." 71"
timer(1200,"parse",param)

old Re: Timer error

DC
Admin Off Offline

Quote
cs2d lua cmd timer

timer expects the name of a Lua function as string.
entering some CS2D or Lua commands directly as parameter for timer does not work.
it must be a Lua function name as string (and this string always WITHOUT parameters).
you can only pass ONE parameter to the function that is called by the timer. this parameter is the THIRD parameter of the timer function.

so you have to add a new function to fix it. also: return ends function execution instantly, nothing behind a return is executed at all. so you have to put the return after the timer.
1
2
3
4
5
6
7
8
9
10
11
addhook("spawn","spawnlol")
function spawnlol(id)
	if classes[id]==1 then
		timer(1200,"strip45",id)
		return "45";
	end
end

function strip45(id)
	parse("strip "..id.." 45")
end

edit: sorry, the solution of Textual Context is better and should work as well. it calls the Lua parse function and passes the cs2d script you want to execute as parameter. clever approach
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview