Clear output via code?

I was wondering if there was a way to clear the output using code? I want to do this as I have a bunch of prints I am using to look for a bug.

print('Start')
-- Code
print(1)
-- Code
print(2)
-- Code
print(3)
-- Code
print(4)
-- Code
print('End')

And to find the bug I basically need to continously have this running, and the output can become a mess. So I was wondering if there was something I could put at the top of all this that’d clear any previous prints, so the output only shows the current prints being performed

3 Likes

Well in the output window you can right click and click “Clear Output” or press “CTRL + K” and use comments to comment out unnecessary print statements and try to narrow down the bug to a print statement.

As for your actual question, I don’t think you can clear the output using a script.

Any users can correct me if you can actually clear the output via script.

3 Likes

Unfortunately the closest you can get at the moment is clearing the output manually with Control + K. However, you could create a bunch of blank lines to simulate starting with a fresh new slate.
For instance, this will create 15 blank lines:

for i=1, 15 do
print(string.rep(" ", i%2))
end

Hope you’re able to pinpoint your bug!

3 Likes

Alternatively, since this will count as multiple different prints, you could try just printing one long multi-line string:

print(("\n"):rep(15)) -- prints 15 new line characters
12 Likes

I wouldn’t say you could exactly “clear” the output, but you can pseudo the effect, like what @posatta did. Otherwise, if you wanna clear studio output just do CTRL + K.

local function Clear(Lines)
    print(string.rep("\n", Lines))
end

print("stuff")
wait(1)
Clear(20)
2 Likes

LogService:ClearOutput()

14 Likes

Kinda sad so this method only clears the output line in the studio. It would be nice if it worked in a regular game for the developer console. I would also like to see something like the removal of certain lines of information output, as the author of this topic wanted.

1 Like