Hi. I've been making a SENT for a friend's server and I keep getting a strange error when I spawn it. Can anyone help me figure out why it's doing this?
[CODE]function ENT:Initialize()
ENT:SetModel("models/props/cs_office/plant01.mdl")
ENT:SetSkin(0)
ENT:PhysicsInit(SOLID_VPHYSICS)
ENT:SetMoveType(MOVETYPE_VPHYSICS)
ENT:SetSolid(SOLID_VPHYSICS)
ENT:SetUseType(SIMPLE_USE)
local phys = ENT:GetPhysicsObject()
if phys and phys:IsValid() then phys:Wake() end
end[/CODE]
The above code in init.lue give me this:
[CODE][lua\entities\plant\init.lua:7] attempt to index global 'ENT' (a nil value)
[/CODE]
[highlight](User was banned for this post ("Wrong section" - Gran PC))[/highlight]
Use 'self' rather than ENT.
So, it'd be like this:
[QUOTE=Lee Dumber;36679713]
[CODE]function ENT:Initialize()
self:SetModel("models/props/cs_office/plant01.mdl")
self:SetSkin(0)
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
local phys = self:GetPhysicsObject()
if phys and phys:IsValid() then phys:Wake() end
end[/CODE]
[/QUOTE]
[QUOTE=Dizla;36679722]Use 'self' rather than ENT.
So, it'd be like this:[/QUOTE]
Thank you! This solved the problem perfectly.
[QUOTE=Lee Dumber;36679768]Thank you! This solved the problem perfectly.[/QUOTE]
Hopefully you understand why, that is the most important part. No problem, however :)
[QUOTE=Dizla;36679796]Hopefully you understand why, that is the most important part. No problem, however :)[/QUOTE]
Is it because the function is part of ENT so its code needs to use self to refer to ENT?
[QUOTE=Lee Dumber;36679820]Is it because the function is part of ENT so its code needs to use self to refer to ENT?[/QUOTE]
Yeah! Bang on. I'd rather people learned than just copy+pasted and forgot about it!
[QUOTE=Dizla;36679866]Yeah! Bang on. I'd rather people learned than just copy+pasted and forgot about it![/QUOTE]
Thanks. I'm new to Lua but I'm learning some now that I have a project to focus on.
Sorry, you need to Log In to post a reply to this thread.