A very VERY wierd Problem with Clientside vars.

**Objective: **Trying to define a Variable that’s Clientside
**Error: **…\shared.lua:732 attempt to compare nil with number
**Code: ** [lua]
if CLIENT then
function SWEP:Think()

	if self.Lights <= CurTime() then --Line 732
                    --Do somethinf..
		self.Lights = CurTime() + .1
	end
	if self.LightsCanFire >= CurTime() then
            --Something else
	else
            --Another something else:
	end
end

end
–BUT I DO DEFINE IT IN–
function SWEP:Deploy()
self.m_WeaponDeploySpeed=1.4
self.Weapon:EmitSound( “displacer_new/weapon/activate.wav” )
self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
self:SetNextPrimaryFire( CurTime() + 1.5 )
self:SetNextSecondaryFire( CurTime() + 1.5 )
self.Idle = true
self.IdleDelay = CurTime() + 1.3
self.ReloadDelay = CurTime() + .3
self.ReloadAnim = true
self.DeploySound = true
if CLIENT then --I also tried it without this, doesnt work
self.Lights = CurTime() + 1.5
self.LightsCanFire = CurTime() + 1.5
end
return true
end
–I also Tried writing a separate Deploy func that’s Clientside, doesn’t help ether.
–I also define those vars here
function SWEP:PrimaryAttack()
if self.Owner:KeyDown(IN_RELOAD) then
if self.Exit == 0 then
local tr = self.Owner:GetEyeTrace()
timer.Simple(1, self.Portal, self, “exit”, “make”, “normal”)
self.Effect = true
self.EffectDelay = CurTime() + 1
self:SetNextPrimaryFire(CurTime()+2)
self:SetNextSecondaryFire(CurTime()+2)
self.LightsCanFire = CurTime() + 2
self.Idle = true
self.IdleDelay = CurTime() + 1.5
self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
self.Weapon:EmitSound( “displacer_new/weapon/charge.wav” )
self.Exit = 1
elseif self.Exit == 1 then
self:SetNextPrimaryFire(CurTime()+2)
self:SetNextSecondaryFire(CurTime()+2)
self.LightsCanFire = CurTime() + 2
self.Idle = true
self.IdleDelay = CurTime() + 1.5
timer.Simple(1, self.Portal, self, “exit”, “take”, “normal”)
self.RemoveEffectEx = true
self.EffectDelay = CurTime() + 1
self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
self.Weapon:EmitSound( “displacer_new/weapon/charge.wav” )
self.Exit = 0
end
else
self:SetNextPrimaryFire(CurTime()+.4)
self:SetNextSecondaryFire(CurTime()+.4)
self.LightsCanFire = CurTime() + .4
self.Idle = true
self.IdleDelay = CurTime() + .5
timer.Simple(.01, self.Teleport, self, “ent”) --For some reason, making it a timer fixed it…
end
end
–and here

function SWEP:SecondaryAttack()
if self.Owner:KeyDown(IN_RELOAD) then
if self.Enter == 0 then
timer.Simple(1, self.Portal, self, “enter”, “make”, “normal”)
local tr = self.Owner:GetEyeTrace()
self.SpawnPos = tr.HitPos - (self.Owner:GetAimVector() * 72) + Vector(0,0,25)
self.Effect = true
self.EffectDelay = CurTime() + 1
self:SetNextPrimaryFire(CurTime()+2)
self:SetNextSecondaryFire(CurTime()+2)
self.LightsCanFire = CurTime() + 2
self.Idle = true
self.IdleDelay = CurTime() + 1.5
self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
self.Weapon:EmitSound( “displacer_new/weapon/charge.wav” )
self.Enter = 1
elseif self.Enter == 1 then
timer.Simple(1, self.Portal, self,“enter”, “take”, “normal”)
self.RemoveEffectEn = true
self.EffectDelay = CurTime() + 1
self:SetNextPrimaryFire(CurTime()+2)
self:SetNextSecondaryFire(CurTime()+2)
self.LightsCanFire = CurTime() + 2
self.Idle = true
self.IdleDelay = CurTime() + 1.5
self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
self.Weapon:EmitSound( “displacer_new/weapon/charge.wav” )
self.Enter = 0
end
else
self:SetNextPrimaryFire(CurTime()+2)
self:SetNextSecondaryFire(CurTime()+2)
self.LightsCanFire = CurTime() + 2
self.Idle = true
self.IdleDelay = CurTime() + 1.5
self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
timer.Simple(1, self.Teleport, self, “self”)
self.Weapon:EmitSound( “displacer_new/weapon/charge.wav” )
end
end
–Everything else works, only those 2 vars don’t.

[/lua]

**Notes: **I intentionally do not define self.Lights in the attacks. Any extra notes I included are included in the Lua If anyone can help, I would be very grateful.

Its nil, so you need to define it or check if the light variable exists.
[LUA]//Only run if it exists
if self.Lights <= CurTime() then
self.Lights = CurTime() + .1
end
//Check if exists, if not set it
if !self.Lights or self.Lights <= CurTime() then
self.Lights = CurTime() + .1
end[/LUA]

I do define it, in The DEPLOY func, but… yeah

You check it before the Deploy function is ran. Place the code bellow the Deploy() function.

maybe think is running before deploy? add a print to each function and see what runs in what order, if that’s the case then a nil check will stop the error till the value is good

[editline]29th May 2011[/editline]

:ninja:ed

so, wait, where should I put the code you gave me?

Did you really write the code by yourself?

Choose which one fits best for you and apply it look at the error line.