Forum

> > CS2D > Scripts > Timer var
Forums overviewCS2D overview Scripts overviewLog in to reply

English Timer var

2 replies
To the start Previous 1 Next To the start

old Timer var

Quattro
GAME BANNED Off Offline

Quote
How to pass a variable to timer for function?

The timer below shows freeimage error, trying to pass nil but number required (it doesn't get id value)

1
2
3
4
5
6
7
8
timer(5000,'close_personal_stats',id,1)

function close_personal_stats(id)
    freeimage(images[id])
    images[id] = 0
    for i = 1, 34 do parse('hudtxt2 '..id..' '..i) end
    if flag[6] == 0 then for i = 35, 43 do parse('hudtxt2 '..id..' '..i) end end
end

old Re: Timer var

Yates
Reviewer Off Offline

Quote
You could always parse as Lua.

1
timer(5000, "parse", "lua close_personal_stats("..id..")")

Or something like that. I literally have not done this for a few years, excuse me if this is incorrect syntax.

I believe your error is saying that it cannot find the
images
table with the associated
id
(trying to parse nil but cs2d lua cmd freeimage requires a number and it has got a nil value because your
images[id]
could not be found).

You always have to
tonumber
when using a timer function and passing int values. So maybe this will fix it instead of having to parse lua within the timer:

1
2
3
4
5
6
function close_personal_stats(id)
	id = tonumber(id)
	freeimage(images[id])
	images[id] = nil -- always set to nil
	-- the rest
end

old Re: Timer var

Quattro
GAME BANNED Off Offline

Quote
I forgot to check if timer() converts it to string. No wonders it didn't work looking like this:
freeimage(images["1"])


Thanks!!
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview