• Adding To A Table Via ConCommands
    10 replies, posted
Could i make a Concommand that would add a string to a table then another that would print out everything in the table?
Yes
I could Probably Make The Concommand To Print out everything in the table But how Could I make a concommand that would add to a table
Google is awesome. -snip, see Gambit's code-
[QUOTE=crazyscouter;45616559]Google is awesome. [code] local mytable = {"one", "two", "three"}; concommand.Add("test", function(cmd, ply, args) args = table.Concat(args, " "); table.insert(mytable, args); PrintTable(mytable); end) [/code][/QUOTE] If I'm not mistaken, you would end up with: [code] { [1] = "one" [2] = "two" [3] = "three" [4] = { [1] = "some" [2] = "arg" } } [/code] You should probably use [URL="http://wiki.garrysmod.com/page/table/Add"]table.Add[/URL]. [code] local mytable = {"one", "two", "three"}; concommand.Add("test", function(cmd, ply, args) table.Add(mytable, args); PrintTable(mytable); end) [/code]
The op asked for a string to be added, so I used table.Concat() which concatenates the values from a table to a string, so it should work. Either method is fine, OP
He didnt say what string he wanted :l
I know. But if he wants to do like "thiscommand Hello, how are you?", the string he typed, would be passed as a table( obviously ), therefore, I reconcatenated the table so he would have his initial string. Also if the op can't figure out how to print a table, I doubt he's going to be making some advanced console commands :v:
True. If that OP wants to add the string, do not waste calls compiling the table: [code] concommand.Add("test", function(cmd, ply, args, raw) table.Add(mytable, raw); end [/code]
[QUOTE=G4MB!T;45617100]True. If that OP wants to add the string, do not waste calls compiling the table: [code] concommand.Add("test", function(cmd, ply, args, raw) table.Add(mytable, raw); end [/code][/QUOTE] Ignore my other posts then, didn't even know that fourth arg was passed :suicide:
[QUOTE=crazyscouter;45617104]Ignore my other posts then, didn't even know that fourth arg was passed :suicide:[/QUOTE] Its a secret, so dont tell anyone.
Sorry, you need to Log In to post a reply to this thread.