Is there a way to print() without a newline at the end?

When I send text to the Output pane using print(), it always gets a newline appended, so that the next text I send is on the next line. Is there a way of printing text that doesn’t do this?

The documentation states that io.write() doesn’t add a newline but it doesn’t seem to be supported at the moment.

Would it make sense in your app to concatenate the output strings and then print() them?

This would be nice to know.

Blanchot: “Would it make sense in your app to concatenate the output strings and then print() them?”

Afraid not. That would simplify matters, but in this case I need letters to appear one at a time, and if I only get one letter per line they quickly scroll off the screen.

You could use one of the various font libraries (I’ve just posted an update to mine) and draw the characters on the screen rather than in the output area.

Cornered prey will often mount a final desperate attack – Book of Qi

Said in reverse, when cornered advance desperately.

Said for this, when you cannot retreat 1 line, advance 19 blank ones, to give the illusion of standing still.

The elapsed time is simply to slow down the demo.



function setup()
    x = "a"
    e = ElapsedTime
end

function draw()
    background(0, 0, 0)
    if ElapsedTime - e > 1 then
        print(x)
        x = x .. "a"
        e = ElapsedTime
        for i = 1,19 do print() end
    end
end

However this will wreck the print buffer within 10 uses :slight_smile:

Shows count of use, delay from last use, and adjusts to length



function setup()
    x = "a"
    y = 1
    e = ElapsedTime
end

function draw()
    background(0, 0, 0)
    --if ElapsedTime - e > .1 then
        print(y, ElapsedTime - e)
        print(x)
        x = x .. "a"
        y = y + 1
        e = ElapsedTime
        for i = 1,math.floor(19 - (y/40))do print() end
    --end
end

it’s still gonna hammer print() - print seems to get exponentially slower the bigger the buffer gets.

use a drawn font. Mine, someone else’s, doesn’t matter.

I have a “console()” class - meant to directly replace print() with something that’s transparently overlaid on the screen (so you can use it fullscreen). I’ll see about packaging it up for use.

Speed improvement, reduced print() calls


function setup()
    x = ""
    y = 1
    e = ElapsedTime
end

function draw()
    background(0, 0, 0)
    --if ElapsedTime - e > .1 then
        print(y, ElapsedTime - e)
        x = x .. "a"
        y = y + 1
        e = ElapsedTime
        z = ""
        for i = 1,math.floor(19 - (y/40))do z = z .. "\
" end
        print(x .. z)
    --end
end

yes, that’s the choice… slow or draw to screen (console/font)

or use watch()

It would be great if one of the buttons displayed on screen for fullscreen would flip to standard and vice-versa.

Ipda41001: “or use watch”

Not a bad idea. Sadly, watch() doesn’t seem to play nicely with strings, or any non-numeric variable.

@Davidhof: I’m going to add the ability for watch() to accept an arbitrary Lua expression, instead of only a numeric global.

Ok. Thanks for all the good suggestions, everyone. I’ll probably use @Andrew_Stacey ’ s font library. It’s impressive.