MasterTobi Posted January 3, 2009 Share Posted January 3, 2009 Hey i have a porblem the code: function hey(source,command,parameter) outputChatBox("Player 1 say: "parameter,source) end addCommandHandler("live",live) if i type /hey test test test test in the Chatbox then comes in the Chatbox test and not test test test test i have to change the function to function hey(source,command,parameter,parameter2,parameter3,parameter4) but this is f**k if i type more dann parameter4 also /hey 1 2 3 4 5 then comes Player 1 say : 1 2 3 4 and i need the 1 2 3 4 in one parameter this goes??? i hope you understand me i´m a german player thx MasterTobi Link to comment
Ace_Gambit Posted January 3, 2009 Share Posted January 3, 2009 You can use table.concat to join arguments as one string. Edit: To be more specific: function foo(...) print(table.concat(arg, " ")) end Link to comment
MasterTobi Posted January 3, 2009 Author Share Posted January 3, 2009 hm i´m a stupid -.- function hey(source,command,parameter) outputChatBox("Player 1 say: "print(table.concat(parameter, " ")),source) 1 Error argument #1 to 'concat' (table expected, got string) Link to comment
Ace_Gambit Posted January 3, 2009 Share Posted January 3, 2009 function hey(source,command,...) Link to comment
MasterTobi Posted January 3, 2009 Author Share Posted January 3, 2009 oh i dont understand you can you give me the complet code , pls thx Link to comment
50p Posted January 3, 2009 Share Posted January 3, 2009 First of all, read wiki over and over again! It's the first source where you should get all the info from! -- DO NOT USE source IN FUNCTION PARAMETERS! function hey( plr, command, ... ) -- ... <- 3 dots represent rest of the parameters passed to the function -- (in this case all the words that player types after /live) outputChatBox("Player 1 say: " .. table.concat( arg ), plr ) end addCommandHandler("live", hey) Link to comment
MasterTobi Posted January 4, 2009 Author Share Posted January 4, 2009 ah okey thx @ all Link to comment
Lordy Posted January 6, 2009 Share Posted January 6, 2009 I'm just clearing it up shouldn't it be table.concat({...}, " ") instead of table.concat(arg, " ") ? Does arg already mean all the arguments in a table? Link to comment
robhol Posted January 6, 2009 Share Posted January 6, 2009 I'm just clearing it up shouldn't it be table.concat({...}, " ") instead of table.concat(arg, " ") ? Does arg already mean all the arguments in a table? You're right. You need to use {...} Link to comment
Ace_Gambit Posted January 6, 2009 Share Posted January 6, 2009 I'm just clearing it up shouldn't it be table.concat({...}, " ") instead of table.concat(arg, " ") ? Does arg already mean all the arguments in a table? That's what he wants, concatenate all passed parameters after the command as one string. The "arg" variable represents the table of parameters passed by the variable argument list "..." in the function call. So table.concat(arg, " ") is correct as well. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now