Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Output gap between lines

Can we get this to be a settable parameter? I've been doing a lot of code in XCode, and whenever I come back to Codea, the output pane could really benefit from way less space between print() calls. I'm talkin Terminal style output.

Comments

  • dave1707dave1707 Mod
    Posts: 7,546

    Is this the kind of print output you would like ( the second group ). It looks like a normal print does multiple new lines whereas printing from a table only does 1. I would like the second group to be the normal print. If I want more space between lines, I can add more new lines.

    function setup()
        tab={}
        for z=1,10 do
            print(z)
            table.insert(tab,z)
        end
        print(table.concat(tab,"\n"))
    end
    
  • Posts: 289

    i always dont know why there're empty lines the first group

  • yes, that's exactly what i'm looking for, @dave1707

  • dave1707dave1707 Mod
    Posts: 7,546

    @matkatmusic Unless something changes with the print statement in a future release, the only way to get print like that is to put it into a table and then use the table.concat command to print it. But there will be a gap between seperate table.concat statements. If you take my code above and duplicate the last print statement several times, you'll see what I'm saying.

  • Posts: 2,020

    overwrite the print command:

    local oldPrint = print
    function print(...)
       oldPrint(table.concat({...}),"\n"))
    end
    
    print("Don't","like","a","function?","Replace","it")
    
  • edited August 2015 Posts: 212

    Figured it out, so there is no line between calls to "print":

    local oldPrint = print
    local consoleOutput = {}
    function print(...)
        output.clear()
        local args={...}
        table.insert( consoleOutput, table.concat( args, " " ) )
        oldPrint( table.concat(consoleOutput, "\n" ) )
    end
    
    function setup()
        for z=1,10 do
            table.insert(consoleOutput,z)
        end
        print( "abc ")
        print( "12345" )
    end
    
    function touched(touch) 
        print( touch.x, touch.y )
    end
    

    The only bug I've found is that you can't do "print( self )", where self is a class instance

  • dave1707dave1707 Mod
    Posts: 7,546

    @matkatmusic Nice job. That routine will be very useful.

  • @matkatmusic

    you can apply the tostring function on all args to ensure there is no bug with print(self)

Sign In or Register to comment.