MasterTobi Posted January 3, 2009 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
Ace_Gambit Posted January 3, 2009 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 Development blog Kings of San Andreas
MasterTobi Posted January 3, 2009 Author 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)
Ace_Gambit Posted January 3, 2009 Posted January 3, 2009 function hey(source,command,...) Development blog Kings of San Andreas
MasterTobi Posted January 3, 2009 Author Posted January 3, 2009 oh i dont understand you can you give me the complet code , pls thx
50p Posted January 3, 2009 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) - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
Lordy Posted January 6, 2009 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?
robhol Posted January 6, 2009 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 {...} Do NOT PM ME for help unless invited. - New MTA Script Editor Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.
Ace_Gambit Posted January 6, 2009 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. Development blog Kings of San Andreas
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