1. Post #1
    Anti-Flag's Avatar
    December 2008
    375 Posts
    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
     function setatoone (a = 1)
     if( a == 1 )
       print( "A has been set to one. I suck." )
     end
     concommand.Add("test", setatoone )
    
    Thanks

  2. Post #2
    Gold Member
    Crazy Quebec's Avatar
    May 2008
    2,449 Posts
    That's basicly it (except you forgot an end), also all the info you need is on the wiki :http://wiki.garrysmod.com/?title=Concommand.Add

  3. Post #3
    Anti-Flag's Avatar
    December 2008
    375 Posts
    That's basicly it (except you forgot an end), also all the info you need is on the wiki :http://wiki.garrysmod.com/?title=Concommand.Add
    That gmod wiki is what confused me. Where is the end missing?

  4. Post #4
    Ask Xyxen about L-Leaf.
    mcd1992's Avatar
    March 2008
    313 Posts
    Anti-Flag; posted:
    That gmod wiki is what confused me. Where is the end missing?
    at the end of the if statement

    function setatoone (a = 1)
     if( a == 1 )
       print( "A has been set to one. I suck." )
     end
    end
     concommand.Add("test", setatoone )
    

  5. Post #5
    Anti-Flag's Avatar
    December 2008
    375 Posts
    at the end of the if statement

    function setatoone (a = 1)
     if( a == 1 )
       print( "A has been set to one. I suck." )
     end
    end
     concommand.Add("test", setatoone )
    
    Oh so each little indent needs an end?

  6. Post #6
    Ask Xyxen about L-Leaf.
    mcd1992's Avatar
    March 2008
    313 Posts
    technically yea, if statements must have an end and functions must have an end

  7. Post #7
    cloudwolf's Avatar
    February 2007
    50 Posts
    if you use a function an if statement or a for or while loop you need to have an end.

  8. Post #8
    moomooplatt's Avatar
    April 2006
    53 Posts
    Scope, my dear Watson, Scope.

  9. Post #9
    Anti-Flag's Avatar
    December 2008
    375 Posts
    "=" 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

  10. Post #10
    cloudwolf's Avatar
    February 2007
    50 Posts
    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)
    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)
    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.

  11. Post #11
    Anti-Flag's Avatar
    December 2008
    375 Posts
    meow!