English Multiple Parameters in a Timer.

9 replies
Goto Page
To the start Previous 1 Next To the start
Up
Goo
User
Offline Off
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.

Code:
1
timer(1000,"meditateStage2",id,x,y)

This is the timer I need fixed.
Any help will be appreciated.
03.04.18 11:25:51 pm
Up
Speedfreak
User
Offline Off
Code:
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())
04.04.18 12:27:37 am
Up
Waldin
User
Offline Off
ow i lost my sys folder... well i had a fast written version of user EnderCrypt's file cs2d Timer2 - easy timer! (4) but well, download and use it :p
user Waldin (2014) has written:
can be create 3D option for tiles on 3D
user DC (2014) has written:
@user Waldin: This is a 2D game. there are no 3D tiles.
changelog (2017) has written:
ADDED Experimental 3D rendering mode
04.04.18 12:37:38 am
Up
VADemon
User
Offline Off
https://youtu.be/OlX8havmldo | thread cs2d 【東方】Bad Apple!! 【影絵】 in CS2D | Propaganda, Werbung für Waren (Reklame), Lehren und Ideen, besonders auf dem Gebiete der Politik, um Anhänger zu werben; z.B. Wahlpropaganda durch Versammlungen, Rundfunkreden, Plakate und Flugblätter
04.04.18 12:47:46 am
Up
Goo
User
Offline Off
user Speedfreak has written:
Code:
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())

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))
04.04.18 12:43:20 pm
Up
Nekomata
User
Offline Off

Seconding this. I use this script everywhere.
04.04.18 05:54:58 pm
Up
Bowlinghead
User
Offline Off
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:
Code:
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
Share time limited free games here
04.04.18 07:40:58 pm
Up
Goo
User
Offline Off
@user Nekomata: & @user VADemon: Thanks it works
04.04.18 09:12:33 pm
Up
Masea
Super User
Offline Off
@user Bowlinghead: Are you really sure that will work? What about this one:
Code:
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.
Create and design your GUI easy and fast: file cs2d GUI Framework (12) | Go deep of the darkness and try your intrepidity: file cs2d Outlast 2 Modification (25)
04.04.18 09:36:14 pm
Up
Bowlinghead
User
Offline Off
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
To the start Previous 1 Next To the start