• Cant access variable in SWEP?
    2 replies, posted
Im editing the lockpick in DRP (the shared.lua file obviously) and I have added a variable at the top of the file like so: [code] if SERVER then SWEP.SpeedOfPick = 30 end [/code] Then at the bottom of the file I have a netmessage receive function like so: [code] if SERVER then net.Receive("upgradeSpeed", function(len, ply) -- edited out surrounding shit here self.SpeedOfPick = 20 -- returns nil end end) [/code] Then I get this: attempt to index global 'self' (a nil value) Why? I declared it so it should work fine.
You didn't declare it inside the function (2nd argument of net.Receive). If you want to set something on the player that has sent the net message then do ply.SpeedOfPick = 20 instead. In other words, self only works if you are executing functions via function meta:func()
meta.func( self ) is identical to meta:func( ) as meta.func( self, blah ) is identical to meta:func( blah ), but Netheous is right, you don't have self assigned, and because it isn't assigned it returns that the table or variable expected is nil. Further explanation: Just because you have it located in a SWEP file, doesn't mean it will take the self associated within SWEP functions because the net function is in a different realm than SWEP./:. you may be able to access that variable using the exact name: SWEP.xxx -- however it may be nilled when it gets copied into the Weapons table, so if you change it in a SWEP function, the two references may be different.
Sorry, you need to Log In to post a reply to this thread.