[ERROR] attempt to index local 'self' (a nil value)

Timer Failed! [Simple][@gamemodes/halo/entities/weapons/halo_dm_shotgun/shared.lua (line 208)]

[ERROR] gamemodes/halo/entities/weapons/halo_dm_shotgun/shared.lua:190: attempt to index local ‘self’ (a nil value)

  1. unknown - gamemodes/halo/entities/weapons/halo_dm_shotgun/shared.lua:190

line 208:
[lua]
timer.Simple(0.75, self.SetIdle, self)
[/lua]

line 190:
[lua]
self.Weapon:SendWeaponAnim( ACT_VM_IDLE )
[/lua]

Been trying to add some halo weps to server… having some issues…

timer.Simple doesn’t work like that anymore

I don’t understand. this is the entire timer code
[lua]
function SWEP:Deploy()
local IdleAnim = math.random( 1, 10 )

self.Weapon:EmitSound(Sound("weapons/hshotgun/shotgundraw.wav"))
self.Weapon:SendWeaponAnim( ACT_VM_DRAW )

if (IdleAnim != 5) then return end
timer.Simple(0.75, self.SetIdle, self)

end
[/lua]

you can’t pass function parameters to timer.Simple anymore, read the wiki article i linked and look at the example

old functionality:
[lua]timer.Simple(5, ply.ChatPrint, ply, “OH GOD WHAT THE FUCK”)[/lua]

new functionality:
[lua]timer.Simple(5, function() ply:ChatPrint(“OH GOD WHAT THE FUCK”) end)[/lua]

I don’t understand how to fix the code then :confused: i tried but i am very new to lua

[lua]timer.Simple(0.75, self.SetIdle, self)[/lua]
change to
[lua]timer.Simple(0.75, function() self:SetIdle() end)[/lua]

I’m also getting an error here
[lua]
timer.Create( “Reload_” … self.Weapon:EntIndex(), 0.45, 17- self.Weapon:Clip1(), self.PerformReload, self )
[/lua]

[lua]
timer.Create( “Reload_” … self.Weapon:EntIndex(), 0.45, 17- self.Weapon:Clip1(), function self:PerformReload() end)
[/lua]

That should fix it. Just a tip, though, when you get an error, post the error, because we generally don’t like to guess at errors.

You’re not going to be spoonfed, the answer has been given already. Stop being lazy and apply what you already know from what you have just seen.

I tried to do that, I am very bad at this, I applied what I learned to something different, then I tried removing self, but I forgot to add the function… sorry

[editline]28th September 2013[/editline]

Thanks, you forgot to bracket the function, but besides that it works, thanks

Final working code… for anyone wondering/ future reference
[lua]
timer.Create( “Reload_” … self.Weapon:EntIndex(), 0.45, 17- self.Weapon:Clip1(), function() self:PerformReload() end)
[/lua]

Sorry about that. I’m multitasking, working on my own gamemode.

No problem, thanks for your help, very much appreciated