SWEP:Holster() problem: attempt to index global 'self' (a nil value)
3 replies, posted
weapons/weapon_katana/shared.lua:277: attempt to index global 'self' (a nil value)
[lua]
--This is line 277, mentioned in the error
function SWEP.Holster()
self.Owner:SetRunSpeed(500)
self.Owner:SetWalkSpeed(250)
end
[/lua]
Not quite sure what I'm doing wrong. I'm editing a SWEP for a friend so that it increases your run & walk speeds as you use the SWEP, then removes the changes when you holster the SWEP. Am I not calling the method right here, or is something else the problem?
[lua]function SWEP:Holster()[/lua]
Use a : instead of a .
I suddenly feel like an idiot, thanks. Now that I look that over, it makes sense, function SWEP.Holster() would effectively be overriding the function holster, and thus accomplishing nothing.
SWEP:Holster overrides it the same as SWEP.Holster. These two functions are the same:
[lua]function SWEP.Holster(self)
print(self)
end
function SWEP:Holster()
print(self)
end[/lua]
The only difference is a colon inherently provides a "self" argument referring to the object the function is used on, in this case the "SWEP".
Sorry, you need to Log In to post a reply to this thread.