I have a question.

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.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: I have a question.

Post by TechnoCat »

com_1 wrote:LEN, MOD, SPLIT
Assuming this is asking for length, modulus, and string split, the answer is yes. This is because the entire Lua language is at your disposal.
Length http://www.lua.org/manual/5.1/manual.html#2.5.5
Modulus http://www.lua.org/manual/5.1/manual.html#2.5.1
Split http://lua-users.org/wiki/SplitJoin
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: I have a question.

Post by Robin »

com_1 wrote:LEN, MOD, SPLIT - is it possible on "Love2D" ?

If yes then how ?
LEN: if you mean the length of a string or table, #somestring or #sometable
MOD: if you mean the remainder of a division, a % b
SPLIT: if you mean splitting a string into substrings by means of delimiters, see http://love2d.org/wiki/String_exploding
Help us help you: attach a .love.
User avatar
com_1
Prole
Posts: 44
Joined: Fri Oct 22, 2010 11:54 pm
Location: No Comment

Re: I have a question.

Post by com_1 »

Thanks for your help.

It will take time, something to understand how it works.

I first saw(see) what LUA only a week ago. (thanks "Love2D")
User avatar
com_1
Prole
Posts: 44
Joined: Fri Oct 22, 2010 11:54 pm
Location: No Comment

Re: I have a question.

Post by com_1 »

font = love.graphics.setFont('courbi.ttf', 15);

// Not working ?
height = Font:getHeight(font)
width = Font:getWidth(font)


Where is the problem, please help.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: I have a question.

Post by TechnoCat »

com_1 wrote:font = love.graphics.setFont('courbi.ttf', 15);

// Not working ?
height = Font:getHeight(font)
width = Font:getWidth(font)


Where is the problem, please help.
you probably wanted

Code: Select all

height = font:getHeight()
width = font:getWidth()
EDIT: DISREGARD THIS POST. IT IS WRONG.
Last edited by TechnoCat on Wed Oct 27, 2010 12:44 pm, edited 2 times in total.
User avatar
com_1
Prole
Posts: 44
Joined: Fri Oct 22, 2010 11:54 pm
Location: No Comment

Re: I have a question.

Post by com_1 »

font = love.graphics.setFont('courbi.ttf', 15)

height = Font:getHeight(font)
width = Font:getWidth(font)

Not working !!!


love.graphics.setFont('courbi.ttf', 15)

height = Font:getHeight()
width = Font:getWidth()

Not working !!!


Where is the PROBLEM, please ?
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: I have a question.

Post by TechnoCat »

com_1 wrote:font = love.graphics.setFont('courbi.ttf', 15)

height = Font:getHeight(font)
width = Font:getWidth(font)

Not working !!!


love.graphics.setFont('courbi.ttf', 15)

height = Font:getHeight()
width = Font:getWidth()

Not working !!!


Where is the PROBLEM, please ?
font = love.graphics.setFont('courbi.ttf', 15)
You are storing your font object in the variable 'font', notice the lowercase 'f'.
Then later you are trying to reference it with Font, with a capital 'F'.

I repeat:

Code: Select all

height = font:getHeight()
width = font:getWidth()
EDIT: DISREGARD THIS POST. IT IS WRONG.
Last edited by TechnoCat on Wed Oct 27, 2010 12:44 pm, edited 1 time in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: I have a question.

Post by bartbes »

Now wait a second... I don't think setFont returns a font object, does it? (It does not.)
User avatar
com_1
Prole
Posts: 44
Joined: Fri Oct 22, 2010 11:54 pm
Location: No Comment

Re: I have a question.

Post by com_1 »

function love.load()
font = love.graphics.setFont("courbi.ttf", 15);
height = font:getHeight();
width = font:getWidth();
end

function love.draw()
love.graphics.print("my project",100,100,0,1,1);
end

Please, update this code.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: I have a question.

Post by kikito »

I think you need to use newFont first, and then use setFont - like this:

Code: Select all

function love.load()
  font = love.graphics.newFont("courbi.ttf", 15); --changed 'setFont' to 'newFont'
  height = font:getHeight();
end

function love.draw()
  love.graphics.setFont(font); -- invoked setFont here
  width = font:getWidth("my project"); -- moved getWidth here and added the string
  love.graphics.print("my project",100,100,0,1,1);
end
Notice that you are not really using 'height' and 'width' at all; the program will work exactly the same if you do this:

Code: Select all

function love.load()
  font = love.graphics.newFont("courbi.ttf", 15);
end

function love.draw()
  love.graphics.setFont(font);
  love.graphics.print("my project",100,100); -- the 0,1,1 parameters have default values, you don't need to add them
end
(btw guys, I still think that love.graphics.setFont(filename, size) and love.graphics.setFont(size) are a bad idea - they lead to confusion, as seen here. Separating font loading / creation from font setting is The Right Thing To Do)

EDIT: getWith needs the string
Last edited by kikito on Wed Oct 27, 2010 10:18 am, edited 1 time in total.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 3 guests