[SOLVED] How to make a linebreak?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
YounYokel
Prole
Posts: 39
Joined: Thu Oct 03, 2019 5:57 pm

[SOLVED] How to make a linebreak?

Post 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 =)
Last edited by YounYokel on Sun Oct 06, 2019 11:21 am, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to make a linebreak?

Post 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
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: How to make a linebreak?

Post by ivan »

Also, you can use real line breaks with the [[ ]] operator.
User avatar
YounYokel
Prole
Posts: 39
Joined: Thu Oct 03, 2019 5:57 pm

Re: How to make a linebreak?

Post 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
User avatar
YounYokel
Prole
Posts: 39
Joined: Thu Oct 03, 2019 5:57 pm

Re: How to make a linebreak?

Post 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.
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: How to make a linebreak?

Post 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.
User avatar
YounYokel
Prole
Posts: 39
Joined: Thu Oct 03, 2019 5:57 pm

Re: How to make a linebreak?

Post 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 =)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 50 guests