• I is confused.
    10 replies, posted
  • Avatar of Anti-Flag
  • So I want to know how to correctly use concommands and functions... Tell me if this is on the right track because I don't have access to gmod right now [lua] function setatoone (a = 1) if( a == 1 ) print( "A has been set to one. I suck." ) end concommand.Add("test", setatoone ) [/lua] Thanks
  • Avatar of Crazy Quebec
  • That's basicly it (except you forgot an end), also all the info you need is on the wiki :[url]http://wiki.garrysmod.com/?title=Concommand.Add[/url]
  • Avatar of Anti-Flag
  • [QUOTE=Crazy Quebec;16276627]That's basicly it (except you forgot an end), also all the info you need is on the wiki :[url]http://wiki.garrysmod.com/?title=Concommand.Add[/url][/QUOTE] That gmod wiki is what confused me. Where is the end missing?
  • Avatar of mcd1992
  • [QUOTE=Anti-Flag;]That gmod wiki is what confused me. Where is the end missing?[/QUOTE] at the end of the if statement [lua] function setatoone (a = 1) if( a == 1 ) print( "A has been set to one. I suck." ) end end concommand.Add("test", setatoone ) [/lua]
  • Avatar of Anti-Flag
  • [QUOTE=mcd1992;16277611]at the end of the if statement [lua] function setatoone (a = 1) if( a == 1 ) print( "A has been set to one. I suck." ) end end concommand.Add("test", setatoone ) [/lua][/QUOTE] Oh so each little indent needs an end?
  • Avatar of mcd1992
  • technically yea, if statements must have an end and functions must have an end
  • Avatar of cloudwolf
  • if you use a function an if statement or a for or while loop you need to have an end.
  • Avatar of Anti-Flag
  • "=" expected near ")" or maybe the other way around? I don't have accesss to gmod but that's what it does when I open the script in GMOD
  • Avatar of cloudwolf
  • You completely mis understand arguments. for a console command if you type it in it has 3 arguments(make that more but 3 to pay attention to) [lua]function saymymessage(ply,cmd,args) local argss="" for k,v in pairs(args) do argss=argss..v end RunConsoleCommand("say",ply:Nick().."just ran"..cmd.."with args"..argss) end concommand.Add("test",saymymessage)[/lua] now if you type in console test BOO it will make you say anti-fla just ran test with args BOO you cannot set anything within those parenthesis at the top of the function all it simply does is pass information from one point to another (aka arguments) so in a practical use you could send information from a local variable in a function to another function to use or you could also get returned info but that gets into a little more complex. so your function name(a=1) is invalid syntax.