• Self is nil in my entity's custom function?
    3 replies, posted
When I use the variable 'self' inside a custom function I created, it returns nil. But in the picture below my code it's possible to use self inside a custom function. How can I use self in my custom function? [CODE] function ENT:Explode() print(self) -- Sample code local effectdata = EffectData() effectdata:SetMagnitude( 2 ) effectdata:SetOrigin( self:GetPos() ) util.Effect( "HelicopterMegaBomb", effectdata ) end [/CODE] [IMG]http://i.imgur.com/v251gjV.png[/IMG]
Well the ent is a table of data if I'm not mistaken and you have to use the PrintTable function to print it. Someone correct me if I'm wrong.
Thanks but that wasn't the case. table expected, got nil
My mistake. I was calling the function with self.Explode() not self:Explode() [CODE] function ENT:OnTakeDamage( dmginfo ) print(self) self.Explode() end function ENT:Explode(pos) print(self) end [/CODE]
Sorry, you need to Log In to post a reply to this thread.