SWEP Error

Hello FacePunch users,
Recently I have started my path into the programming language of Lua, being an experienced programmer, and decided to try and learn the language.
I have grabbed the basic concepts and tried to make a SWEP. I used this tutorial and followed it closely. I understand all the code and attempted to make my own SWEP. I successfully created the weapon, but I came into some unsolvable errors.
The current error is this:



{ERROR} addons/rockich_gun/lua/weapons/rockich_gun.lua:57: bad key to string index (number expected, got string)
  1. error - [C]:-1
   2. __index - lua/includes/extensions/string.lua:262
    3. ThrowObject - addons/rockich_gun/lua/weapons/rockich_gun.lua:57
     4. unknown - addons/rockich_gun/lua/weapons/rockich_gun.lua:48


This is my SWEP file:



--Information
AddCSLuaFile()

SWEP.PrintName 		= "Rockich Gun"
SWEP.Author 		= "Bagelriffic"
SWEP.Instructions 	= "Shoots the thrills of Rockichtry"

--Spawn Info
SWEP.Spawnable = true
SWEP.AdminOnly = false
SWEP.UseHands = true

--Ammo
SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip 	= -1
SWEP.Primary.Automatic 		= true
SWEP.Primary.Ammo 			= "none"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= true
SWEP.Secondary.Ammo			= "none"

--More Info
SWEP.Weight 			= 5
SWEP.AutoSwitchTo 		= false
SWEP.AutoSwitchFrom		= false

SWEP.Slot = 1
SWEP.SlotPos = 2
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true

--Models
SWEP.ViewModel			= "models/weapons/c_smg1.mdl"
SWEP.WorldModel			= "models/weapons/w_smg1.mdl"

local ShootSound = Sound( "Metal.SawbladeStick" )

function SWEP:Think()
end

function SWEP:Reload()
end

function SWEP:PrimaryAttack() --THE NEXT LINE IS LINE 48 #######################################
	self.Weapon:SetNextPrimaryFire( CurTime() + 0.5)
	self.ThrowObject( "models/props/cs_italy/bananna.mdl" )
end

function SWEP:SecondaryAttack()
	self.ThrowObject( "models/props_interiors/books02.mdl" )
end

function SWEP:ThrowObject(model_file)
	--[[ #####################################  ##########################This next line is where the error is LINE 57 ]]--
	self:EmitSound( ShootSound )
	
	if( CLIENT ) then return end
	
	local ent = ents.Create( "prop_physics" )
	
	if( !IsValid( ent ) ) then return end
	
	ent:SetModel( model_file )
	
	ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
	ent:SetAngles( self.Owner:EyeAngles() )
	ent:Spawn()
	
	local phys = ent:GetPhysicsObject()
	if ( !IsValid( phys ) ) then ent:Remove() return end
	
	local velocity = self.Owner:GetAimVector()
	velocity = velocity * 500
	velocity = velocity + (VectorRand() * 100)
	phys:ApplyForceCenter( velocity )
	
	cleanup.Add( self.Owner, "props", ent)
	
	undo.Create( "Thrown_Object" )
		undo.AddEntity( ent)
		undo.SetPlayer( self.Owner)
	undo.Finish()
end


From my observations, it seems to be that the variables are not functioning correctly, whether that is from lack of importing the correct files or what ever else it could be, as whenever I omit the line of code “self:EmitSound( ShootSound )” (which is the first error) there is another error relating to another function which uses another variable, “ent:SetModel( model_file )”.

Hope someone can help me, Thanks in advance

You never told us which like is 57, which is 48.

Oh, I do apologize.
I will update the post
This is the line that is causing the error


self:EmitSound( ShootSound )

Read the arguments there, and fill in the ones you haven’t got in there.

In the PrimaryAttack function:


self.ThrowObject( "models/props/cs_italy/bananna.mdl" )

should be


self:ThrowObject( "models/props/cs_italy/bananna.mdl" )

Replacing the dot . with a colon :

Nah, EmitSound can take no args and just use the default value of 100 for those two arguments.

Thanks. Solved it.