Variable question

If you use say…


 
 if( a == 1 )
   print( "Yes!" )
 end
 

What exactly sets the variable to 0 or 1? Most importantly how would you assign a console command to set a to 1?

waitwaitwait lemme guess this is it rite?



 if( a == 1 )
   print( "Yes!" )
 end
 concommand.Add("test", a = 1)


it didn’t work as far as my knowledge goes i typed test in console and it wasnt a command

ok well


a=1

would set a to equal 1 yes but your concommand idea is wrong. A variable is a string an integer a Boolean or a function(because a function in Lua is basically a variable). So i’ll show you multiple ways to set a variable through console. easiest way is.
[lua]function setmyvar()
local var= 1
end
concommand.Add(“test”,setmyvar) [/lua]
that just simply sets the value to 1 every time you run the command test in console simple yes? well you can go further.
[lua]local myvar=“string”
function newstring(ply,command,args)
myvar= args
end
concommand.Add(“newstringis”,newstring)[/lua]

I may be wrong, but when you add the concommand it is looking for you to type “test” then it looks in your code for a function named ‘a = 1’.

Since there is no function named that you can’t run it.

If you created a function outside the if and named it testVar or something, then used the concommand.Add(“test”, testVar) it would work. You should also, set an else in the if so if it isn’t 1 then it says No. So you know if it wasn’t set at least to 1. And you know the if is being run.

http://gc3008.k12.sd.us/crazy_cat25.jpg

How to create a fucktion “a=1”?