View Single Post
11/10/20, 02:30 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
https://wiki.esoui.com/Main_Page
Lower bottom right -> Templates:
Scene Manager: On scene change
Fragments in a scene: On fragment state change (e.g. Hide control as menu opens)

The game uses SCENES which are a kind of "visible tables storing controls and data", and each scene got 1 to n fragments attached.
You are able to react on the scenes and/or fragments as they are going to be shown (showing), are shown (shown), going to be hidden (hiding) or are hidden (hidden) again via a callback function.

If you register your own fragment, add your Top Level Control to it and thena dd this fragment to an exisitng scene like the hud or hud_ui the standard show/hide functions will handle the show/hide of your fragment as well, automatically.

Edit about your code:
You should not mix up the usage of . and : in your code.

https://wiki.esoui.com/SimpleNotebookTutorial/part5

function SimpleStats.OnWindowMoveStop()
function SimpleStats:RestorePosition

As your SimpleStats is ONLY a anormal table, defined via = {}, and it's not a kind of object or class defined via ZO_Object:Subclass() or ZO_Object:New() I'd go with the normal . instead of a :.

In this curren simple example it does not make a big difference.
But if you will use objects and "subclasses" one day you'll get into trouble if you only use . as the parameters of the functions do not automatically add the object (self) and you manually need to isert it as always 1st parameter.

Difference shown with an example:
Lua Code:
  1. local myClass = ZO_Object:Subclass()
  2. ... --function myClass:New() and maybe :Initialize() within :New here
  3. function myClass:Test(param1)
  4.  d("This is a test: " ..tostring(param1))
  5. end
  6.  
  7. local myObject = myClass:New()
  8. myObject:Test("YEAH!")
  9. --output: This is a test YEAH!
This was using a class and an object created from this class.
Classes within ESO lua are just tables using the setmetatable functions to "inherit data from the tables above", so no real classes lie within other languages.

Now an example where the created object will be calling the Test function without :, only by .
Lua Code:
  1. local myClass = ZO_Object:Subclass()
  2. ... --function myClass:New() and maybe :Initialize() within :New here
  3. function myClass:Test(param1)
  4.  d("This is a test: " ..tostring(param1))
  5.  --variable self is known and points to the created object of myClass -> see myObject below
  6. end
  7.  
  8. local myObject = myClass:New()
  9.  
  10. myObject.Test("YEAH!")
  11. --> Will fail as you use the . instead of : and this way self (pointer to myObject) is not given automatically. The function will take the 1st parameter "YEAH!" as your self object and fail.
  12.  
  13. myObject.Test(pointertToMyObject, "YEAH!")
  14. --output: This is a test YEAH!
  15. --Same as myObject:Test("YEAH!")



Now to the normal addon table approach
Lua Code:
  1. local myAddon = {} --Just a normal table
  2.  
  3. function myAddon.Test(param1)
  4.  d("This is a test: " ..tostring(param1))
  5. end
  6.  
  7. myAddon:Test("YEAH!")
  8. --> Will fail as :Test is not known and myAddon is not an object, just the pointer to your table.
  9.  
  10. myAddon.Test("YEAH!")
  11. --output: This is a test YEAH!

Last edited by Baertram : 12/16/20 at 10:51 AM.
  Reply With Quote