Page 1 of 1

[solved]Problem with fonts.

Posted: Wed Mar 23, 2022 10:55 pm
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.

Re: Problem with fonts.

Posted: Thu Mar 24, 2022 1:57 am
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.

Re: Problem with fonts.

Posted: Thu Mar 24, 2022 8:18 pm
by astragor
I've solved the problem, i had another call to my fonction that return nil for pfont.
Thanks at all.