Help with removing the commas in an RGB argument for a chat command and then sorting them

Hey developers, so I am developing an admin script and I have a command for changing the lighting ambient. The command is pretty simple, you just break the message up into 4 separate arguments, the first one being the command itself, the second one being the ‘R’ (Red) value, the third one being the ‘G’ (Green) value and the fourth one being the ‘B’ (Blue) value. And then you just check to make sure the RGB values are above 0 and less than 255 and then you are ready to go. However, I would like a system where instead of you doing 255 0 0 for example, you would instead do 255,0,0. I already have a system of removing commas in a single argument using gmatch, like seen here:

for _, arg in pairs(args) do
	for s in arg:gmatch("[^,%s]+") do
		--Code here...
	end
end

But I would like to know how I could sort the three values into order, because breaking the arguments up won’t be enough, so how would I sort the args into the correct ‘RGB’ (1,2,3) order to assign the RGB value to the ambient property.

Sorry for any confusion, I can elaborate if needed.

Maybe put them in a table and use table.sort

1 Like

I did think of that originally but that will sort them in ascending order, so if you had 255,0,0 for example, it would sort it as 0,0,255 (which would give you blue not red).

1 Like

Maybe try something like this

local val = "10,20,30"

for w in string.gmatch(val,"%d+") do
 print(w)
end
1 Like

Hm, I will try and implement it now, thanks!