Old 06-25-2009   #1
alec
Pro-Servers Dev
 
alec's Avatar
 
Join Date: Apr 2009
Location: Where else?
Posts: 18
alec is on a distinguished roadalec is on a distinguished roadalec is on a distinguished road
Quick question of my own

Hey all

Can anyone quickly tell me how to go about writing a command that accepts multiple arguments which are separated into multiple variables, but the last variable can be a number of words, without using something like:

addCommand("me","cmdMe",1)

It would be ideal to be able to give a message to the player in the event of incorrect input, instead of nothing - hence why I'd rather not use addCommand's third parameter.

Please advise!

Thanks
__________________

alec is offline   Reply With Quote
Old 06-25-2009   #2
Mex
Registered User
 
Join Date: Nov 2008
Posts: 44
Mex is on a distinguished roadMex is on a distinguished roadMex is on a distinguished road
yo, this should work:

Code:
addCommand("me", "cmdMe")

function cmdMe(PlayerID, ArgumentOne, ArgumentTwo, ArgumentThree, ArgumentFour, ...)
	-- the 3 dots mean to fetch everything the player typed after ArgumentFour, and put them into an assossiative table called 'arg'.
	-- you could then loop around the table and split them into variables

	-- If the player typed /me is testing a b c d e f g h
	ArgumentOne = "is"
	ArgumentTwo = "testing"
	ArgumentThree = "a"
	ArgumentFour = "b"
	arg[1] = "c"
	arg[2] = "d"
	arg[3] = "e"
	arg[4] = "f"
	arg[5] = "g"
	arg[6] = "h"
end
Mex is offline   Reply With Quote
Old 06-25-2009   #3
alec
Pro-Servers Dev
 
alec's Avatar
 
Join Date: Apr 2009
Location: Where else?
Posts: 18
alec is on a distinguished roadalec is on a distinguished roadalec is on a distinguished road
Thanks Mex!

And here's a function I just threw together to concatenate a table (I'm just used to PHP, etc so I call 'em arrays ):

Code:
function concatArray(Array)
	local At = 1
	local Output = ""
	while Array[At] do
		Output = Output.." "..Array[At]
		At = At + 1
	end
	return string.sub(Output, 2)
end
And here's a /me function built using it.

Code:
function cmdMeTwo(PlayerID, ...)
	outputChatBox("** "..getPlayerName(PlayerID).." "..concatArray(arg),255,255,255,255)
end
addCommand("metwo","cmdMeTwo")
Clearly that's excessive for a /me command but for /sus or anything else that requires text input after other parameters it's just the trick.
__________________

alec is offline   Reply With Quote
Old 06-30-2009   #4
youlikethaaaat
Pro-Servers Dev
Newbie Member
 
Join Date: Apr 2009
Location: Wales
Posts: 7
youlikethaaaat is an unknown quantity at this point
Quote:
Originally Posted by alec View Post
Thanks Mex!

And here's a function I just threw together to concatenate a table (I'm just used to PHP, etc so I call 'em arrays ):

Code:
function concatArray(Array)
	local At = 1
	local Output = ""
	while Array[At] do
		Output = Output.." "..Array[At]
		At = At + 1
	end
	return string.sub(Output, 2)
end

Wouldn't it be better to just use:
Code:
table.concat({...}, " ")
instead of writing a function to do basically the same thing..?
youlikethaaaat is offline   Reply With Quote
Old 07-02-2009   #5
alec
Pro-Servers Dev
 
alec's Avatar
 
Join Date: Apr 2009
Location: Where else?
Posts: 18
alec is on a distinguished roadalec is on a distinguished roadalec is on a distinguished road
You could have told me that before :p
__________________

alec is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -6. The time now is 07:42 PM.