Script wont work

Here is a rundown of my code:



function SWEP:Initialize()
	SWEP.Secret = false 
	util.PrecacheSound(SWEP.Primary.Sound)
	concommand.Add( "togglesupersecretoption", function() 
		if SWEP.Secret = false then
			SWEP.Secret = true
			print( "Secret On")
			SWEP.Primary.Sound = ("secret.mp3")
		elseif Swep.Secret = true then
			SWEP.Secret = false 
			print ("Secret Off")
			SWEP.Primary.Sound = ("swing.mp3")
		end
	end )
end


Anybody see any problems? Sorry, I’m an lua noob.
Ignore the capitalization, self-corrected.

if you’re INSIDE a function of your own SWEP, don’t use SWEP.variable, use self.variable instead.

You use == for equal to not =
[lua]
function SWEP:Initialize()
self.Secret = false
util.PrecacheSound(SWEP.Primary.Sound)
concommand.Add( “togglesupersecretoption”, function()
if self.Secret = false then
self.Secret == true
print( “Secret On”)
self.Primary.Sound = (“secret.mp3”)
elseif self.Secret == true then
self.Secret = false
print (“Secret Off”)
self.Primary.Sound = (“swing.mp3”)
end
end )
end
[/lua]

Wouldn’t it be:
[lua]
function SWEP:Initialize()
self.Secret == false
util.PrecacheSound(SWEP.Primary.Sound)
concommand.Add( “togglesupersecretoption”, function()
if self.Secret == false then
self.Secret == true
print( “Secret On”)
self.Primary.Sound == (“secret.mp3”)
elseif self.Secret == true then
self.Secret == false
print (“Secret Off”)
self.Primary.Sound = (“swing.mp3”)
end
end )
end
[/lua]

To add to the above (all correct), you’re testing whether something is true/false. You don’t need to compare it with true or with false, you can just use it as-is:

[lua]function SWEP:Initialize()
self.Secret = false
util.PrecacheSound(self.Primary.Sound)
concommand.Add( “togglesupersecretoption”, function()
if self.Secret then
self.Secret = false
print (“Secret Off”)
self.Primary.Sound = (“swing.mp3”)
else
self.Secret = true
print( “Secret On”)
self.Primary.Sound = (“secret.mp3”)
end
end )
end[/lua]

This is about as grammatically confusing as it gets…

Don’t create concommands inside of functions.


local sound1 = Sound( "swing.mp3" )
local sound2 = Sound( "secret.mp3" )

concommand.Add( "togglesupersecretoption", function( ply )
   local wep = ply:GetActiveWeapon()
   if ( wep:GetClass() == "weapon_whatever" ) then
      if ( self.Primary.Sound == sound1 ) then
         self.Primary.Sound = sound2
         ply:ChatPrint( "Secret on!" )
      else
         self.Primary.Sound = sound1
         ply:ChatPrint( "Secret off!" )
      end
   end
end )

Would doing a concommand in a function make an error?

No, but you’re re-creating the command each time the function is called, no use in that.