Forum

> > CS2D > Scripts > timer not works
Forums overviewCS2D overview Scripts overviewLog in to reply

English timer not works

3 replies
To the start Previous 1 Next To the start

old timer not works

sheeL
User Off Offline

Quote
I have 3 timer values
just does not work
I want a solution to this problem
if possible someone give me an example, i'll send one

1
timer(1400,"WP.GetValue",a1,a2,a3)

thx

old Re: timer not works

Alistaire
User Off Offline

Quote
timer(ms, 'function', parameter)

There's only one parameter you can send.
What you could do, tho is this;

1
2
3
4
5
6
7
8
9
10
11
12
function splitString(str)
	local c = {}
	for word in string.gmatch(str, '[^%s]+') do
		table.insert(c, word)
	end
	return c
end

function WP.GetValue(string)
	local par = splitString(string)
	--par[1] is now a1, par[2] is a2 and par[3] is a3
end

old Re: timer not works

sheeL
User Off Offline

Quote
i am manipulating the values ​​a1,a2​​,a3,
look,

1
2
3
4
5
6
7
8
if WP.Command == "!get" then
	if player(pl,"exists") then
	a1 = score[pl]
	a2 = frag[pl]
	a3 = deaths[pl]
	return 1
	end
end

old Re: timer not works

VaiN
User Off Offline

Quote
To elaborate a bit on Alistaire's response. Concatenate the parameters as a string.

1
timer(1400,"WP.GetValue", a1 .. "," .. a2 .. "," .. a3)

Your GetValue function would need to parse the parameters. You could just get them as a table as follows (untested):
1
2
3
4
5
6
7
8
function split_params(str)
	if not str then return nil end
	local tbl = {}
	for word in string.gmatch(str, "[^,]+") do
		table.insert(tbl, word)
	end
	return tbl
end
This will split a string at "," into a table (should work for strings that have spaces as well) as string values. Don't forget to use tonumber() for numeric values if you are doing any math ect.

Hope that helps.

Some other advice, if you are working with player-specific data, it's best to use a table to store all of that data together.
1
2
3
a1 = stats[id].score
a2 = stats[id].frags
a3 = stats[id].deaths
It's better practice than using multiple tables for related info. Then you can easily iterate through the stats of each player at once, rather than three separate iterations. Just my opinion.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview