Forum

> > CS2D > Scripts > Multiple Parameters in a Timer.
Forums overviewCS2D overview Scripts overviewLog in to reply

English Multiple Parameters in a Timer.

9 replies
To the start Previous 1 Next To the start

old Multiple Parameters in a Timer.

Mami Tomoe
User Off Offline

Quote
I would've searched but the search doesn't appear neither in the Search / FAQ or when creating a thread. Probably a problem in my browser that will be fixed at some point...

I need to be able to create a timer that calls a function with multiple parameters but it doesn't work because after the first parameter the next one goes into the count parameter.

1
timer(1000,"meditateStage2",id,x,y)
This is the timer I need fixed.
Any help will be appreciated.

old Re: Multiple Parameters in a Timer.

Speedfreak
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
timers = {}

function advtmr(time,func,var)
if not time then	for k,v in pairs(timers) do	timers[k] = 1	end	return	end
local ar
for i = 1,#timers+1 do	if not timers[i] then	ar = i	break	end	end
timers[ar] = {f = func,v = var}
timer(time,"exectimer",ar)
end

function exectimer(array)
local ar = tonumber(array)
if not timers[ar] then	return
elseif type(timers[ar]) == "table" then	timers[ar].f(timers[ar].v and unpack(timers[ar].v))
end
timers[ar] = nil
end

Usage: advtimer(time_in_ms,function,{variableA,variableB})
Example: advtimer(2500,timertesting,{1,5,"three"})

This should work

EDIT: you can can also call advtimer() with no parameters to cancel all active timers (very similar to function freetimer())

old Re: Multiple Parameters in a Timer.

Mami Tomoe
User Off Offline

Quote
user Speedfreak has written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
timers = {}

function advtmr(time,func,var)
if not time then	for k,v in pairs(timers) do	timers[k] = 1	end	return	end
local ar
for i = 1,#timers+1 do	if not timers[i] then	ar = i	break	end	end
timers[ar] = {f = func,v = var}
timer(time,"exectimer",ar)
end

function exectimer(array)
local ar = tonumber(array)
if not timers[ar] then	return
elseif type(timers[ar]) == "table" then	timers[ar].f(timers[ar].v and unpack(timers[ar].v))
end
timers[ar] = nil
end

Usage: advtimer(time_in_ms,function,{variableA,variableB})
Example: advtimer(2500,timertesting,{1,5,"three"})

This should work

EDIT: you can can also call advtimer() with no parameters to cancel all active timers (very similar to function freetimer())

1
LUA ERROR: sys/lua/Master_Yi/main.lua:58: attempt to call field 'f' (a string value)
in the code:
1
timers[ar].f(timers[ar].v and unpack(timers[ar].v))

old Re: Multiple Parameters in a Timer.

Bowlinghead
User Off Offline

Quote
cs2d lua cmd timer
Cant you just do:
param= tostring(id..","..x..","..y)
timer(1000, "meditateStage2", param, x, y)?

I can remember a super easy way but I dont find the thread

Edit:
http://www.unrealsoftware.de/forum_posts.php?post=324914&start=0
Here they went an even uglier way - but hey its original:
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
Its not what I ment tho

old Re: Multiple Parameters in a Timer.

Masea
Super User Off Offline

Quote
@user Bowlinghead: Are you really sure that will work? What about this one:
1
2
3
function example(a,b)
     timer(1000,"parse","lua example2("..a..", "..b..")",0)
end
Since Lua does not read variables within a string like you did.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview