WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   API Changed in SetFont ? (https://www.wowinterface.com/forums/showthread.php?t=58283)

gmarco 10-14-20 02:37 PM

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

gmarco 10-14-20 02:45 PM

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.

Fizzlemizz 10-14-20 03:36 PM

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)

Seerah 10-14-20 03:55 PM

Nah, he's using colon notation. That part's good.

Are you sure the object you're passing through is actually a fontstring, though?

Fizzlemizz 10-14-20 04:14 PM

Code:

Locals:
obj = "AchievementFont_Small"

looks like a font name (or rather object) to me ;)

gmarco 10-14-20 04:23 PM

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.

gmarco 10-14-20 04:33 PM

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 :)

Fizzlemizz 10-14-20 04:35 PM

Tied myself up overthinking with the first example code use of passing in a string.

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

gmarco 10-14-20 04:38 PM

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.

gmarco 10-14-20 04:42 PM

Quote:

Originally Posted by Fizzlemizz (Post 337141)
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

SDPhantom 10-14-20 04:57 PM

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.

gmarco 10-14-20 05:55 PM

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 ! :)

Seerah 10-14-20 08:59 PM

Quote:

Originally Posted by Fizzlemizz (Post 337136)
Code:

Locals:
obj = "AchievementFont_Small"

looks like a font name (or rather object) to me ;)

:o Missed that part and apparently didn't read your last few words. I'm going to go back to music now.

SDPhantom 10-14-20 11:53 PM

Quote:

Originally Posted by gmarco (Post 337151)
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.


All times are GMT -6. The time now is 07:46 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI