How can I easily convert multiple arguments/table values into a single string?

  1. What do you want to achieve? A short and simple way of converting multiple arguments into a single string for an admin system.

  2. What is the issue? It’s too large and is pretty hard to work with.

  3. What solutions have you tried so far? I’ve looked but I’ve not seen anything that helps

This is the code to convert the arguments currently:

			local reasonFunction = function()
				local reasonString = ""
				for i=1, (#args - 1) do
					reasonString = reasonString.." "..tostring(args[i+1])
				end
				return reasonString
			end
			local reasonCoroutine = coroutine.wrap(reasonFunction)
			local reasonString = reasonCoroutine()

There is also obviously a memory issue with this (local reasonString = "") so I have to use a coroutine.

Can’t you use table.concat in your case?

local tbl = {"Steve", "Bob", "Mom"}
print(table.concat(tbl, " ")) -- Steve Bob Mom
--Gets all the entries in the table and makes them into a string, separating
--Them using the 2nd given argument, in our case, a space

Judging from your usage, you’d have to first make a table with everything besides the first index, table.move should help in this case

local tempTable = {}
table.move(args, 2, 4, 1, tempTable)

Will get everything besides the first thing

1 Like

just use table.concat. What is table.concat() actually do?

1 Like

Just noting my friend helped me with this, and I’m pretty garbage with tables. I’ll have a look into table.concat.

1 Like