• Arguments
    12 replies, posted
I can't find any specific tutorial or definition on the wiki defining arguments. I would like someone to explain please, like how I can use them in a function or derma. I see them in tons of places such as a console command being ran from a derma menu and what they type like sv_gravity 100 in the text box and click a derma button that says send sends it and it changes the gravity. Something like that, they put the args there. Like ..[Arg1].. or something like that Help please. Thanks, Justin
[QUOTE=Justin37111;18035025]I can't find any specific tutorial or definition on the wiki defining arguments. I would like someone to explain please, like how I can use them in a function or derma. I see them in tons of places such as a console command being ran from a derma menu and what they type like sv_gravity 100 in the text box and click a derma button that says send sends it and it changes the gravity. Something like that, they put the args there. Like ..[Arg1].. or something like that Help please. Thanks, Justin[/QUOTE] An argument is simply the information you pass to a function for it to use. Example [lua] function PrintMyNumber(number) -- Defining a function that takes a single argument print("My number is "..number) -- Printing a string concatenated with whatever we passed to the function. if number == 7 then --Defining a condition print(number.." rocks!") end end PrintMyNumber(1) -- prints : My number is 1 PrintMyNumber(3) -- prints : My number is 3 PrintMyNumber(7) -- prints : My number is 7 ; 7 rocks! PrintMyNumber("a potato!") -- prints : My number is a potato! [/lua] Functions that are already defined take certain argument types which you can find in the wiki. [url]http://wiki.garrysmod.com/?title=Lua[/url]
What about arguments that take in the text that is put into the text box and sends it to the server? Such as sv_gravity 100, also if i said I searched the wiki you don't have to put the wiki at the bottom, lol. I like your help though
[QUOTE=Justin37111;18035388]What about arguments that take in the text that is put into the text box and sends it to the server? Such as sv_gravity 100, also if i said I searched the wiki you don't have to put the wiki at the bottom, lol. I like your help though[/QUOTE] Console commands are created with [url=http://wiki.garrysmod.com/?title=Concommand.Add]Concommand.Add[/url]. It makes it so that each command links to a certain function. That function will automatically take 3 arguments : - the player who entered the command - the command itself - a table containing all arguments entered after the command so if type : mycommand 4 1 2 and link it to a function such as function cc(ply,cmd,args) args will be equal to {4,1,2} args[1] is 4 args[2] is 1 args[3] is 2 Also what did you search on the wiki? I'll make it easier to find that.
EDIT: Quebec answered it.
I looked in tutorials, searched "Arguments" and "Args" looked through some of the stuff. But like I was saying, what about the sv_gravity thing? I seen people make a text box come up have them type something in and it does that command with rcon before it so it is like using rcon_password and then rcon <command> but instead its with derma.
If you look at concommand.Add (Link Above) you'll see that it gives the player who used it as a command. You put the derma files on the client, and send a usermessage to that client that causes the derma to spawn. [url]http://wiki.garrysmod.com/?title=Umsg[/url] Is what you'll want for that. Doing something like sv_gravity 100 is easy. Again, concommand.Add will give the function you specify the arguments as well. You just set the gravity to those arguments. If you really don't get arguments in general, I could restore my post above.
The sv_gravity thing, like I explained, is a console command. One that is pre-defined tough so it has nothing to do with lua. In that case the the number is still an argument tough. Also rcon (another console command) is for using commands on a dedicated server. [editline]09:50PM[/editline] :ninja:
HOLY SHIT! You guys do not know what the fuck I am saying. I already know about concommand.Add that is fucking easy! Derma menu, text box, enter command, hit an enter button next to the text box, takes that text and lets say it is "say 4000000" it prints Console: 40000000 in the chat because that chatbox uses rcon commands, get it? rcon before the command after it is entered. Jesus, understand now? If not I will break it down even more, it was posted before, and thanks.
Fail? [lua] DButton.DoClick = function() LocalPlayer():ConCommand(DTextBox:GetValue()) end[/lua] Why does anyone help you.
[quote=Justin37111]I can't find any specific tutorial or definition on the wiki [b]defining arguments[/b].[/quote] We're trying to help you, and it sounded a lot like you weren't sure what an argument was. Don't bite the hand that feeds. The thing you're talking about would just be like [code]RunConsoleCommand("rcon","command","arg1","arg2")[/code]
That requires you to do rcon_password and enter the rcon pass first.
Yea, yakahughes thank you for the help, you and crazy help the most, =) Love ya
Sorry, you need to Log In to post a reply to this thread.