Weird error when using pistols

Whenever I select a pistol to use I get an error from outside the addon itself

[ERROR] gamemodes/base/entities/weapons/weapon_base/sh_anim.lua:30: bad argument #1 to ‘lower’ (string expected, got nil)

line 30:
[lua] t = string.lower( t )[/lua]

(even though this error might be obvious for some of you. For me its new.)
if anyone knows why this script is wrong, please leave a reply.

Thanks

I can’t tell from the error and just one line why the error is caused but I know string.lower expects a string argument, and for some reason you are passing null (nothing)



t = NULL

t = "Mega AWESOME capsLOCKING and STUFF"
if (!t == NULL) then
     t = string.lower( t )
else
     t = "WHOOPSIES"
end


I don’t know much about how lua handles NULL or nil, but somethings like this can handle if t is never set.

Is this a pistol you’re making, a pistol from a pack, or what?

This is a handgun from a swep pack I’m made in gmod 12 but now im porting it into gmod 13 95% done I just bet these pesky errors when i first deploy a handgun.

the full function is below:
[lua]
local ActIndex = {
[ “pistol” ] = ACT_HL2MP_IDLE_PISTOL,
[ “smg” ] = ACT_HL2MP_IDLE_SMG1,
[ “grenade” ] = ACT_HL2MP_IDLE_GRENADE,
[ “ar2” ] = ACT_HL2MP_IDLE_AR2,
[ “shotgun” ] = ACT_HL2MP_IDLE_SHOTGUN,
[ “rpg” ] = ACT_HL2MP_IDLE_RPG,
[ “physgun” ] = ACT_HL2MP_IDLE_PHYSGUN,
[ “crossbow” ] = ACT_HL2MP_IDLE_CROSSBOW,
[ “melee” ] = ACT_HL2MP_IDLE_MELEE,
[ “slam” ] = ACT_HL2MP_IDLE_SLAM,
[ “normal” ] = ACT_HL2MP_IDLE,
[ “fist” ] = ACT_HL2MP_IDLE_FIST,
[ “melee2” ] = ACT_HL2MP_IDLE_MELEE2,
[ “passive” ] = ACT_HL2MP_IDLE_PASSIVE,
[ “knife” ] = ACT_HL2MP_IDLE_KNIFE,
[ “duel” ] = ACT_HL2MP_IDLE_DUEL,
[ “camera” ] = ACT_HL2MP_IDLE_CAMERA,
[ “revolver” ] = ACT_HL2MP_IDLE_REVOLVER
}

–[[---------------------------------------------------------
Name: SetWeaponHoldType
Desc: Sets up the translation table, to translate from normal
standing idle pose, to holding weapon pose.
-----------------------------------------------------------]]
function SWEP:SetWeaponHoldType( t )

t = string.lower( t )
local index = ActIndex[ t ]

if ( index == nil ) then
	Msg( "SWEP:SetWeaponHoldType - ActIndex[ \""..t.."\" ] isn't set! (defaulting to normal)

" )
t = “normal”
index = ActIndex[ t ]
end

self.ActivityTranslate = {}
self.ActivityTranslate [ ACT_MP_STAND_IDLE ] 				= index
self.ActivityTranslate [ ACT_MP_WALK ] 						= index+1
self.ActivityTranslate [ ACT_MP_RUN ] 						= index+2
self.ActivityTranslate [ ACT_MP_CROUCH_IDLE ] 				= index+3
self.ActivityTranslate [ ACT_MP_CROUCHWALK ] 				= index+4
self.ActivityTranslate [ ACT_MP_ATTACK_STAND_PRIMARYFIRE ] 	= index+5
self.ActivityTranslate [ ACT_MP_ATTACK_CROUCH_PRIMARYFIRE ] = index+5
self.ActivityTranslate [ ACT_MP_RELOAD_STAND ]		 		= index+6
self.ActivityTranslate [ ACT_MP_RELOAD_CROUCH ]		 		= index+6
self.ActivityTranslate [ ACT_MP_JUMP ] 						= index+7
self.ActivityTranslate [ ACT_RANGE_ATTACK1 ] 				= index+8
self.ActivityTranslate [ ACT_MP_SWIM_IDLE ] 				= index+8
self.ActivityTranslate [ ACT_MP_SWIM ] 						= index+9

-- "normal" jump animation doesn't exist
if t == "normal" then
	self.ActivityTranslate [ ACT_MP_JUMP ] = ACT_HL2MP_JUMP_SLAM
end

self:SetupWeaponHoldTypeForAI( t )

end

– Default hold pos is the pistol
SWEP:SetWeaponHoldType( “pistol” )

–[[---------------------------------------------------------
Name: weapon:TranslateActivity( )
Desc: Translate a player’s Activity into a weapon’s activity
So for example, ACT_HL2MP_RUN becomes ACT_HL2MP_RUN_PISTOL
Depending on how you want the player to be holding the weapon
-----------------------------------------------------------]]
function SWEP:TranslateActivity( act )

if ( self.Owner:IsNPC() ) then
	if ( self.ActivityTranslateAI[ act ] ) then
		return self.ActivityTranslateAI[ act ]
	end
	return -1
end

if ( self.ActivityTranslate[ act ] != nil ) then
	return self.ActivityTranslate[ act ]
end

return -1

end [/lua]

You are calling self:SetWeaponHoldType( str ) without any arguments in your code.

I did not make this code this is from the file “sh_amin.lua”

[ERROR] gamemodes/base/entities/weapons/weapon_base/sh_anim.lua:30: bad argument #1 to ‘lower’ (string expected, got nil)

I have no clue whats this about.

In your gun you use that function incorrectly, that’s why it is erroring.