Simple question, what is wrong with this code?
[lua]function ENT:Grow()
ent:SetPos(ent.GetPos + Vector(0,0,5) )
end
timer.Create( “Atimer”, 5, 1, ENT:Grow )[/lua]
It just keeps giving me “Expected arguments at ,”
Simple question, what is wrong with this code?
[lua]function ENT:Grow()
ent:SetPos(ent.GetPos + Vector(0,0,5) )
end
timer.Create( “Atimer”, 5, 1, ENT:Grow )[/lua]
It just keeps giving me “Expected arguments at ,”
I believe it should be
[lua]timer.Create( “Atimer”, 5, 1, ENT.Grow, ENT )[/lua]
have you tried creating the timer like
[lua]
function ENT:Initialize()
timer.Create(“GrowTime”, 5, 1, self:Grow)
end
[/lua]
That’s right because these two are the same:
[lua]
Ent:Grow()
–same as
Ent.Grow(Ent)
[/lua]
The : is just a short way of doing it. The first argument is hidden and called self to the function it belongs to.
timer.Create( "Atimer", 5, 1, function()
ent:SetPos(ent.GetPos + Vector(0,0,5) )
end
end
No?
[lua]
function ENT:Initialize()
timer.Create(“Atimer”, 5, 1, self.Grow)
end
function ENT:Grow()
self:SetPos(self:GetPos() + Vector(0, 0, 5))
end
[/lua]
That should work.
[lua]
function ENT:Initialize()
timer.Create( “Atimer”, 5, 1, self.Grow, self )
end
function ENT:Grow()
self:SetPos(self:GetPos() + Vector(0,0,5) )
end
[/lua]
Ohh, I forgot about it. Thanks Ralle for correction.
It worked to a degree, but I want the timer to start again when it’s finished, which it did when it was not in the ENT:Initialize() but I can’t take it out if ENT:Initialize() because it will make it impossible to get the self variable if you get what I mean.
The 1 in the timer function tells it how many times to run, change it to 0 and it will never stop.