[solved]Problem with fonts.

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
astragor
Prole
Posts: 2
Joined: Fri Aug 09, 2019 12:08 am

[solved]Problem with fonts.

Post by astragor »

Hello I have an error that i dont understand.
I'm developing a GUI and I have a problem when I try to pass a filename as a parameter.

I wrote my function like this:

Code: Select all

GUI.addCheckbox(px,py,pw,ph,pcolor,pborderSize,pborderColor,pshape,ptext,pfont,ptextsize)
        local cb ={}
        ....
        cb.text = {}
        cb.text.font = love.graphics.newFont(pfont, ptextsize)
And I call like this.

Code: Select all

...
 MyGUI.addCheckbox(10 + elements[j].x + i*40, elements[j].y + 10,30,40,colWHITE,2,colBLACK,"roundrect", i+2, "font/arl.ttf", 24)
When I call my function I get this error message

Code: Select all

Error: bad argument #1 to '?' (filename, File, or FileData expected)
stack traceback:
    [love "boot.lua"]:345: in function <[love "boot.lua"]:341>
    [C]: at 0x7ff9b1d52630
    [C]: in function 'newFont'
    GUI.lua:39: in function 'addCheckbox'
    main.lua:21: in function 'load'
    [love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
    [C]: in function 'xpcall'
    [love "boot.lua"]:361: in function <[love "boot.lua"]:348>
    [C]: in function 'xpcall'
Process exited with code 1
Whereas if I write this in my function it works:

Code: Select all

cb.text.font = love.graphics.newFont("font/arl.ttf", ptextsize)
Can you help me please ?

Of course I can not put my text in hard.
Last edited by astragor on Thu Mar 24, 2022 8:18 pm, edited 1 time in total.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Problem with fonts.

Post by ReFreezed »

Looking at the stack traceback, the error is happening somewhere in newFont(). In the addCheckbox function, print all the arguments to see what they actually are - pfont must have the wrong value.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
astragor
Prole
Posts: 2
Joined: Fri Aug 09, 2019 12:08 am

Re: Problem with fonts.

Post by astragor »

I've solved the problem, i had another call to my fonction that return nil for pfont.
Thanks at all.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests