Multiple Parameters in a Timer.
9 replies



03.04.18 10:05:47 pm
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.
This is the timer I need fixed.
Any help will be appreciated.
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.
Code:
1
timer(1000,"meditateStage2",id,x,y)
This is the timer I need fixed.
Any help will be appreciated.
Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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())
ow i lost my sys folder... well i had a fast written version of
EnderCrypt's
Timer2 - easy timer! (4) but well, download and use it :p




Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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())
Code:
1
LUA ERROR: sys/lua/Master_Yi/main.lua:58: attempt to call field 'f' (a string value)
in the code:
Code:
1
timers[ar].f(timers[ar].v and unpack(timers[ar].v))
Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?

Seconding this. I use this script everywhere.

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:
Code:
1
2
3
4
5
6
7
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
timer(1000,"parse","lua example2(a,b)",0)
end
function example2(a,b)
--some code
end
Its not what I ment tho
Share time limited free games here

Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?
@
Bowlinghead: Are you really sure that will work? What about this one:

Code:
Since Lua does not read variables within a string like you did. 1
2
3
2
3
function example(a,b)
timer(1000,"parse","lua example2("..a..", "..b..")",0)
end
timer(1000,"parse","lua example2("..a..", "..b..")",0)
end
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery:
Outlast II Modification (28)


Yeah it was just a better pick up quote and I didnt see that mistake. In the link you can see the explanation and stuff.
Share time limited free games here




