I want to create a customizedprint()
function that would print the arguments to the console and then also put them in a StringValue
.
I read an article on how to do that. My code is as the following:
function printConsole(...) coroutine.wrap(function(arg) local toPrint="" print(arg) for _,v in pairs(arg) do toPrint=toPrint..tostring(v) end print(toPrint) workspace.ToPrint.Value=workspace.ToPrint.Value..toPrint.."\n" end)(arg) end print("Hi", "there!")
At the for
loop it breaks because arg
is nil
, not a table
.
At print(arg)
it says: "Hi" so it thinks arg
is a string
.
There is no need for coroutine and you pass a nil value anyway. Here:
function printConsole(...) local arg = {...} local toPrint="" print(arg) for _,v in pairs(arg) do toPrint=toPrint..tostring(v) end print(toPrint) workspace.ToPrint.Value=workspace.ToPrint.Value..toPrint.."\n" end print("Hi", "there!")
FYI, roblox allows you to redefine 'print' function itself, so you can do that.