Forum

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

Englisch timer not works

3 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt timer not works

sheeL
User Off Offline

Zitieren
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

alt Re: timer not works

Alistaire
User Off Offline

Zitieren
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

alt Re: timer not works

sheeL
User Off Offline

Zitieren
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

alt Re: timer not works

VaiN
User Off Offline

Zitieren
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.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht