Forum

> > CS2D > Scripts > I'm stuck
Forums overviewCS2D overview Scripts overviewLog in to reply

English I'm stuck

2 replies
To the start Previous 1 Next To the start

old I'm stuck

RIP-HereRestsPlookerbooy
BANNED Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
function totableC( ...)
	local cmd = {}
	t = { ... }
	for _,word in t do
		table.insert(cmd, tostring(word))
	end 
	return cmd
end

STR = totableC(Ubuntu,40,&H0008C3DF,&H00B2EAFF,&H000E0E9D,&H00F622FF,-1,0,0,0,100,100,0,0,1,2,0,8,16,16,16,1)
msg(STR[1])

Please, don't ask me why i'm making this, but seriously I'm stuck. This is like my first time using "..." thing on a script...

I just need everything on this table/string (I don't know what to call it) to be a string on a table
HALP

old Re: I'm stuck

Cure Pikachu
User Off Offline

Quote
https://www.lua.org/pil/5.2.html has written
The three dots (
...
) in the parameter list indicate that the function has a variable number of arguments. When this function is called, all its arguments are collected in a single table, which the function accesses as a hidden parameter named
arg
. Besides those arguments, the
arg
table has an extra field,
n
, with the actual number of arguments collected.

So I think this is how it could be done:
1
2
3
4
5
6
7
8
9
10
function totableC(...)
	local cmd = {}
	for _, word in pairs(arg) do
		table.insert(cmd,tostring(word))
	end
	return cmd
end

STR = totableC("Ubuntu",40,"&H0008C3DF","&H00B2EAFF","&H000E0E9D","&H00F622FF",-1,0,0,0,100,100,0,0,1,2,0,8,16,16,16,1)
msg(STR[1])
edited 3×, last 12.06.24 01:52:48 am

old Re: I'm stuck

RIP-HereRestsPlookerbooy
BANNED Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
function totableC(str)
	local cmd = {}
	str = string.gsub(str, ",", " ")
	for word in string.gmatch(str, "[^%s]+") do
		table.insert(cmd, word)
	end 
	return cmd
end

STR = totableC("Ubuntu,40,&H0008C3DF,&H00B2EAFF,&H000E0E9D,&H00F622FF,-1,0,0,0,100,100,0,0,1,2,0,8,16,16,16,1")
msg(STR[1])

Actually, thanks because you brought me a new idea about a new way to do it and it worked. I tested yours and it didn't work thought.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview