Getting an error even though script apparently works?
2 replies, posted
I'm making a SWEP, and it includes the following code:
[lua]
function SWEP:Think()
if( self.PowerBeamJustFired == true ) then //This variable is determined elsewhere, and is called after firing
self.PowerChargeEndTime = CurTime() + 1
self.PowerBeamJustFired = false
self.ChargeStarted = true
Msg( "JustFired \n" .. CurTime() .. "\n" .. self.PowerChargeEndTime .. "\n" )
end
if( self.Owner:KeyReleased( IN_ATTACK ) && CurTime() > self.PowerChargeEndTime && self.ChargeStarted == true ) then //Line 73
Msg( "Fire \n" .. CurTime() .. "\n" .. self.PowerChargeEndTime .. "\n" )
self.ChargeStarted = false
end
end
[/lua]
However, when I run the code (by firing the weapon, and holding down 1 sec before releasing) I get this in the console:
[lua]
JustFired
4.9649996757507
5.9649996757507
weapons\weapon_armcannon\shared.lua:73: attempt to compare nil with number
Fire
6.6149997711182
5.9649996757507
[/lua]
Line 73 is marked.
Any suggestions on what is causing the error?
Many Thanks
Is the error yellow? My guess is that you are running this code in shared but some of the variables used are only defined on the server.
Thanks - works fine now
Sorry, you need to Log In to post a reply to this thread.