View Single Post
06-20-17, 08:47 PM   #6
aallkkaa
A Warpwood Thunder Caller
 
aallkkaa's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 98
Hi Mandraxon,

I've been messing around WoW Lua for a few years now but I'm still a noob at it. Not saying this to discourage you, more like "I've been playing WoW for a few years now and I'm still a noob at it." The later is as true as the former.

But I do have a few things down.
What I was talking before was about global and local variables and functions.
Global variables or functions can be accessed by any Lua script. The standard Lua functions implemented in WoW are global. The WoW-specific Lua functions a user Lua-script can call are global (NB: WoW has some protected functions which can only be called by other Blizzard functions, not by user-scripts).
For a list of standard Lua functions present in WoW, see: http://wow.gamepedia.com/Lua_functions
For a list of WoW-specific Lua functions, see: http://wow.gamepedia.com/Global_functions
Local functions (and variables) are so declared by prefexing their declaration with the reserved word "local" (no quote of course!) and can only be accessed within the scope in which they were declared. For example, functions declared as local in a .lua file can only be called in that same file (not in another file).
Your "SetFont" function, declared and defined as "local function SetFont(obj, optSize)" etc is an example of a local function.
It can get fairly more complicated than this but for starters I guess this is good enough.

But I'll add this: It's not a good idea to have a global and a local function with the same one name (unless you actually want to replace the global function with the local one; which may also not be such a good idea, though it is possible).
I thought you'd make this mistake, but as Ketho pointed out, what I called "the global SetFont" is NOT a global function but rather a method of the respective font objects. In a way, methods work as functions local to a specific widget, usually a frame (or a font object ...). Simply put, FrameOne:Hide() and FrameTwo:Hide() are not the same, as FrameOne:Hide() hides FrameOne but not FrameTwo, and vice-versa.

So now looking at your code again, I think I know why it's not working. I mean, the logic is mostly correct but there may be something ...
A "font object" can refer to the ones you whose fonts you are trying to change (SystemFont_LargeNamePlate, SystemFont_NamePlate, ...) but they can also be the texts on the player's nameplate text or, another one, the target's nameplate text, or .. some other namplate's text, ...
Now, changing the font for those specific font-objects might work the way your code is doing it but that would be cumbersome to code and a lot heavier on the CPU cycles (possibly reducing FPS rate as a consequence).
Changing the generic nameplate font objects, from which the aforementioned specific font-objects inherit their properties (including font size), would be a one-time task with zero subsequent impact on the game performance. But this can likely NOT be done because said properties are defined in FrameXML which means they are protected.
Yet, there are a couple properties you can usually change for any UI object, scale being one of them. So, despite the fact you may not be able to change the font size (in points), you can likely change its scale.

I can't test it out right now, but try changing your code to this:
EDIT: I tested it (changing the scale of the nameplate system fonts and it did NOT work.
Specifically, running the following command on the game console throws an error that the method (:SetScale) is a nil value (doesn't exist):
Code:
/run SystemFont_NamePlate:SetScale(0.8)
I removed the code I had proposed earlier.

Sorry, I can't help you any further at this point.

Last edited by aallkkaa : 06-21-17 at 07:27 PM.
  Reply With Quote