timer / reference trouble

So, I have been wondering how to do this for a while:

I have this code:

[lua]function cButton:Fade(i)
self.Opacity = self.Opacity + i
end

function cButton:OnCursorEntered()
if not self.IsActive then
timer.Create(“aTimer”, 0.02, 24, self:Fade, 1)
end
end[/lua]

As usual, I get the “argument expected” error when I am using self:Function inside of a timer. What are my options here?

[editline]01:11PM[/editline]

Found out a way to do it for those interested; it’s not very elegant but it gets the job done:

[lua]
function Fade(i, ref)
ref.Opacity = ref.Opacity + i
end

function cButton:OnCursorEntered()
if not self.IsActive then
timer.Create(“aTimer”, 0.02, 24, Fade, 1, self)
end
end
[/lua]

I pass the reference on as a second argument, problem solved.

You could do it the first way too since self:Function(…) is just short for self.Function(self,…) you could just replace
[lua]
timer.Create(“aTimer”, 0.02, 24, self:Fade, 1)
[/lua]
with
[lua]
timer.Create(“aTimer”, 0.02, 24, self.Fade, self, 1)
[/lua]
and it would work:wink: