Quantcast
API Changed in SetFont ? - WoWInterface
Thread Tools Display Modes
10-14-20, 02:37 PM   #1
gmarco
A Rage Talon Dragon Guard
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 310
API Changed in SetFont ?

Hi all,

the next error I am trying to fix is this.

This happens when I try to change fonts attributes calling the function in this way:


Lua Code:
  1. ....
  2.     gmfontset["Roboto"] = {"Roboto-Regular.ttf", "Roboto-Bold.ttf", "Roboto-Italic.ttf", "Roboto-BoldItalic.ttf"}
  3.    
  4.         ....
  5.  
  6.     GMFONTS["N"]    = fontpath .. gmfontset[text][1]
  7.     GMFONTS["B"]    = fontpath .. gmfontset[text][2]
  8.     GMFONTS["BI"]   = fontpath .. gmfontset[text][3]
  9.     GMFONTS["I"]    = fontpath .. gmfontset[text][4]
  10.     GMFONTS["NR"]   = fontpath .. gmfontset[text][1]
  11.  
  12. ......
  13.  
  14. local function SetFont(obj, font, size, style, r, g, b, sr, sg, sb, sox, soy)  
  15.     obj:SetFont(font, size, style)
  16.     if sr and sg and sb then obj:SetShadowColor(sr, sg, sb) end
  17.     if sox and soy then obj:SetShadowOffset(sox, soy) end
  18.     if r and g and b then obj:SetTextColor(r, g, b)
  19.     elseif r then obj:SetAlpha(r) end
  20. end
  21. .....
  22.  
  23.     SetFont("AchievementFont_Small",GMFONTS["B"], 12)
  24.     SetFont("FriendsFont_Large",GMFONTS["N"], 15, nil, nil, nil, nil, 0, 0, 0, 1, -1)
  25.        .... a lot of fonts names here and down :) ....

The error is this:

Lua Code:
  1. 40x gmFonts\core.lua:40: attempt to call method 'SetFont' (a nil value)
  2. [string "@gmFonts\core.lua"]:40: in function <gmFonts\core.lua:39>
  3. [string "@gmFonts\core.lua"]:61: in function <gmFonts\core.lua:47>
  4. [string "@gmFonts\core.lua"]:92: in function <gmFonts\core.lua:79>
  5.  
  6. Locals:
  7. obj = "AchievementFont_Small"
  8. font = "Addons\gmFonts\fonts\Candarab.ttf"
  9. size = 12
  10. style = nil
  11. r = nil
  12. g = nil
  13. b = nil
  14. sr = nil
  15. sg = nil
  16. sb = nil
  17. sox = nil
  18. soy = nil
  19. (*temporary) = nil
  20. (*temporary) = "AchievementFont_Small"
  21. (*temporary) = "Addons\gmFonts\fonts\Candarab.ttf"
  22. (*temporary) = 12
  23. (*temporary) = nil
  24. (*temporary) = "attempt to call method 'SetFont' (a nil value)"

It should be that the fonts names are not global anymore ?

Thanks for any advices
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
10-14-20, 02:45 PM   #2
gmarco
A Rage Talon Dragon Guard
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 310
I have tried also to change the function in this way (taken by Phanx addon):

Lua Code:
  1. local function SetFont(obj, font, size, style, r, g, b, sr, sg, sb, sox, soy)
  2.     if not obj then return end -- TODO: prune things that don't exist anymore
  3.     obj:SetFont(font, size, style)
  4.     if sr and sg and sb then
  5.         obj:SetShadowColor(sr, sg, sb)
  6.     end
  7.     if sox and soy then
  8.         obj:SetShadowOffset(sox, soy)
  9.     end
  10.     if r and g and b then
  11.         obj:SetTextColor(r, g, b)
  12.     elseif r then
  13.         obj:SetAlpha(r)
  14.     end
  15. end

But I got:

Lua Code:
  1. 10x gmFonts\core.lua:41: attempt to call method 'SetFont' (a nil value)
  2. [string "@gmFonts\core.lua"]:41: in function <gmFonts\core.lua:39>
  3. [string "@gmFonts\core.lua"]:69: in function <gmFonts\core.lua:55>
  4. [string "@gmFonts\core.lua"]:100: in function <gmFonts\core.lua:87>
  5.  
  6. Locals:
  7. obj = "AchievementFont_Small"
  8. font = "Addons\gmFonts\fonts\Candarab.ttf"
  9. size = 12
  10. style = nil
  11. r = nil
  12. g = nil
  13. b = nil
  14. sr = 0
  15. sg = 0
  16. sb = 0
  17. sox = 1
  18. soy = -1
  19. (*temporary) = nil
  20. (*temporary) = "AchievementFont_Small"
  21. (*temporary) = "Addons\gmFonts\fonts\Candarab.ttf"
  22. (*temporary) = 12
  23. (*temporary) = nil
  24. (*temporary) = "attempt to call method 'SetFont' (a nil value)"

Thanks again.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
10-14-20, 03:36 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,292
Code:
SetFont("AchievementFont_Small",GMFONTS["B"], 12)
The first parameter of your local SetFont function is supposed to be a FontString widget rather than the font itself.
Code:
SetFont(Frame.FontStringWidget, "AchievementFont_Small",GMFONTS["B"], 12)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
10-14-20, 03:55 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,765
Nah, he's using colon notation. That part's good.

Are you sure the object you're passing through is actually a fontstring, though?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-14-20, 04:14 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,292
Code:
Locals:
obj = "AchievementFont_Small"
looks like a font name (or rather object) to me
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
10-14-20, 04:23 PM   #6
gmarco
A Rage Talon Dragon Guard
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 310
Hi all.

In this moment I am not sure of anything , I know only that it is used to work before 9.0.x


I have a list like:

Lua Code:
  1. SetFont(AchievementFont_Small,              GMFONTS["B"], 12)
  2.     SetFont(FriendsFont_Large,                  GMFONTS["N"], 15, nil, nil, nil, nil, 0, 0, 0, 1, -1)
  3.     SetFont(FriendsFont_Normal,                 GMFONTS["N"], 13, nil, nil, nil, nil, 0, 0, 0, 1, -1)
  4.     SetFont(FriendsFont_Small,                  GMFONTS["N"], 11, nil, nil, nil, nil, 0, 0, 0, 1, -1)
  5.     SetFont(FriendsFont_UserText,               GMFONTS["NR"], 12, nil, nil, nil, nil, 0, 0, 0, 1, -1)
  6.     SetFont(GameTooltipHeader,                  GMFONTS["B"], 15, "OUTLINE")
  7.     SetFont(GameFont_Gigantic,                  GMFONTS["B"], 32, nil, nil, nil, nil, 0, 0, 0, 1, -1)
  8.     SetFont(GameNormalNumberFont,               GMFONTS["B"], 11)
  9.     SetFont(InvoiceFont_Med,                    GMFONTS["I"], 13, nil, 0.15, 0.09, 0.04)
  10.     SetFont(InvoiceFont_Small,                  GMFONTS["I"], 11, nil, 0.15, 0.09, 0.04)
  11.     SetFont(MailFont_Large,                     GMFONTS["I"], 15, nil, 0.15, 0.09, 0.04, 0.54, 0.4, 0.1, 1, -1)
  12.     SetFont(NumberFont_OutlineThick_Mono_Small, GMFONTS["NR"], 13, "OUTLINE")
  13.     SetFont(NumberFont_Outline_Huge,            GMFONTS["NR"], 30, "THICKOUTLINE", 30)
  14.     SetFont(NumberFont_Outline_Large,           GMFONTS["NR"], 17, "OUTLINE")
  15.     SetFont(NumberFont_Outline_Med,             GMFONTS["NR"], 15, "OUTLINE")
  16.     SetFont(NumberFont_Shadow_Med,              GMFONTS["N"], 14)
  17.         ....


For this I was asking if the fonts name where changed in the globals.


Thanks again for the attention.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
10-14-20, 04:33 PM   #7
gmarco
A Rage Talon Dragon Guard
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 310
Hi all again.

Fonts are working now.

I have changed the function call to:

Lua Code:
  1. SetFont(_G.AchievementFont_Small,              GMFONTS["B"], 12)
  2.     SetFont(_G.FriendsFont_Large,                  GMFONTS["N"], 15, nil, nil, nil, nil, 0, 0, 0, 1, -1)
  3.     SetFont(_G.FriendsFont_Normal,                 GMFONTS["N"], 13, nil, nil, nil, nil, 0, 0, 0, 1, -1)
  4.     SetFont(_G.FriendsFont_Small,                  GMFONTS["N"], 11, nil, nil, nil, nil, 0, 0, 0, 1, -1)
  5.     SetFont(_G.FriendsFont_UserText,               GMFONTS["NR"], 12, nil, nil, nil, nil, 0, 0, 0, 1, -1)
  6.     SetFont(_G.GameTooltipHeader,                  GMFONTS["B"], 15, "OUTLINE")
  7.     SetFont(_G.GameFont_Gigantic,                  GMFONTS["B"], 32, nil, nil, nil, nil, 0, 0, 0, 1, -1)

and it seems to work

Now I have to fix another iussue in PhanxConfig-Dropdown that seems to use a frame with a SetBackdrop.

Ahhh it will be a long night
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
10-14-20, 04:35 PM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,292
Tied myself up overthinking with the first example code use of passing in a string.

/run print(FriendsFont_Large.SetFont) works in-game.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
10-14-20, 04:38 PM   #9
gmarco
A Rage Talon Dragon Guard
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 310
Found and fixed ... it was easy now that Fizzlemizz points out to the file of changes from 8.x to 9.x

Lua Code:
  1. local list = CreateFrame("Button", "PhanxConfigDropdown" .. id, dropdown, BackdropTemplateMixin and "BackdropTemplate");

Thanks again.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
10-14-20, 04:42 PM   #10
gmarco
A Rage Talon Dragon Guard
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 310
Originally Posted by Fizzlemizz View Post
Tied myself up overthinking with the first example code use of passing in a string.

/run print(FriendsFont_Large.SetFont) works in-game.

That code works from so long ago.
It was taken from "Tectiles" by tekkub and I never changed so much ...

It is strange but using the _G fixes the code. Why it works in game and not in my addon is a mistery.
But today I am no longer surprised by anything

Thanks again Fizzlemizz
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
10-14-20, 04:57 PM   #11
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,976
Explaining the error is a little complex, but passing a string to your function made the call end up like this.
Code:
("AchievementFont_Small"):SetFont(GMFONTS["B"],12)
When you index a string like a table, Lua redirects to the metatable for strings, the string library. The code above would then transform to this internally because of how colon notation and metatables work.
Code:
string.SetFont("AchievementFont_Small",GMFONTS["B"],12)
There is no string.SetFont(), so Lua throws an attempt to call nil error.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-14-20, 05:55 PM   #12
gmarco
A Rage Talon Dragon Guard
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 310
Thanks for the explanation SDPhantom.

Now I understand a little bit more this error
But this behaviour didn't happen before ? It is changed in 9.0.x ?

Thanks !
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
10-14-20, 08:59 PM   #13
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,765
Originally Posted by Fizzlemizz View Post
Code:
Locals:
obj = "AchievementFont_Small"
looks like a font name (or rather object) to me
Missed that part and apparently didn't read your last few words. I'm going to go back to music now.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-14-20, 11:53 PM   #14
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,976
Originally Posted by gmarco View Post
But this behaviour didn't happen before ? It is changed in 9.0.x ?
Lua has always done this. I don't know how the original function handled it, but as it's written here, it never should have.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-15-20 at 12:01 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » API Changed in SetFont ?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off