Page 1 of 1

[SOLVED] How to make a linebreak?

Posted: Sat Oct 05, 2019 3:06 pm
by YounYokel
Hey guys, do you know a way to create a linebreak like in C++ ( "\n" or std:endl ) for example?

Code: Select all

function love.draw(dt)
    love.graphics.print( "First of all: " .. endline .. "  1. Blah Blah Blah" .. endline .. "  2. Blah Blah Blah" )
end
This would be much easier for creating lists of text, I guess =)

Re: How to make a linebreak?

Posted: Sat Oct 05, 2019 8:52 pm
by pgimeno
What's wrong with

Code: Select all

"\n"
itself?

This works for me:

Code: Select all

function love.draw(dt)
    love.graphics.print( "First of all:\n  1. Blah Blah Blah\n  2. Blah Blah Blah" )
end

Re: How to make a linebreak?

Posted: Sun Oct 06, 2019 4:30 am
by ivan
Also, you can use real line breaks with the [[ ]] operator.

Re: How to make a linebreak?

Posted: Sun Oct 06, 2019 10:57 am
by YounYokel
pgimeno wrote:
Sat Oct 05, 2019 8:52 pm
What's wrong with

Code: Select all

"\n"
itself?

This works for me:

Code: Select all

function love.draw(dt)
    love.graphics.print( "First of all:\n  1. Blah Blah Blah\n  2. Blah Blah Blah" )
end
WHAT !? I really had no idea because I'm new at LUA

Well, I guess topic is solved =P

Re: How to make a linebreak?

Posted: Sun Oct 06, 2019 11:00 am
by YounYokel
ivan wrote:
Sun Oct 06, 2019 4:30 am
Also, you can use real line breaks with the [[ ]] operator.
Really? And how to use them? Post an example please.

Re: How to make a linebreak?

Posted: Sun Oct 06, 2019 11:12 am
by MrFariator

Code: Select all

local myText = [[this is where my text goes
and it will handle linebreaks]]

function love.draw ()
  love.graphics.print(myText, 10, 10)
end
One thing to keep in mind is that all contents between [[]] will be caught, so it will also take the indentation into account if present. Example:

Code: Select all

function love.draw ()
  love.graphics.print([[this is where my text goes
  and it will handle linebreaks]], 10, 10)
end
...will look like this (second line is offset by the indentation present in the code):
Image

You can work around this by just writing the text into a local variable in a non-indented position, like in the first example.

Re: How to make a linebreak?

Posted: Sun Oct 06, 2019 11:21 am
by YounYokel
MrFariator wrote:
Sun Oct 06, 2019 11:12 am

Code: Select all

local myText = [[this is where my text goes
and it will handle linebreaks]]

function love.draw ()
  love.graphics.print(myText, 10, 10)
end
One thing to keep in mind is that all contents between [[]] will be caught, so it will also take the indentation into account if present. Example:

Code: Select all

function love.draw ()
  love.graphics.print([[this is where my text goes
  and it will handle linebreaks]], 10, 10)
end
...will look like this (second line is offset by the indentation present in the code):
Image

You can work around this by just writing the text into a local variable in a non-indented position, like in the first example.
Oh! Thank you, by the way that was the quickest response I ever seen =)