I don't understand Font:getWrap

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
RoToRa
Prole
Posts: 2
Joined: Sat Mar 22, 2014 9:07 pm

I don't understand Font:getWrap

Post by RoToRa »

I'm new to LÖVE and Lua, and I have problems understanding Font:getWrap. I have a simple main.lua containing solely of

Code: Select all

io.stdout:write(love.graphics.getFont():getWrap("Test", 100) .. "\n")
nothing else, so font, font size, etc. all are at default. Since the text should fit without any problems into 100 pixel width, I'd though the function should return 1, however I'm getting 31.

What am I missing? What does the 31 mean?
User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: I don't understand Font:getWrap

Post by DaedalusYoung »

getWrap return two values. Width, and then lines. I think you're only reading the width, currently. To get the lines, read the 2nd value. I think you can do this with select(), otherwise, just make some variables:

Code: Select all

local _, t = love.graphics.getFont():getWrap("Test", 100) .. "\n"
io.stdout:write(t)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: I don't understand Font:getWrap

Post by Robin »

That should be:

Code: Select all

local _, t = love.graphics.getFont():getWrap("Test", 100)
io.stdout:write(t .. "\n")
Help us help you: attach a .love.
User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: I don't understand Font:getWrap

Post by DaedalusYoung »

lol, of course, that's my copy & paste skills messing things up :P
RoToRa
Prole
Posts: 2
Joined: Sat Mar 22, 2014 9:07 pm

Re: I don't understand Font:getWrap

Post by RoToRa »

I feel so dumb. I was sure to read the Wiki page hundreds of time, and somehow I missed that.

Thanks!
Post Reply

Who is online

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