View Single Post
06/05/15, 03:58 AM   #6
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 578
Originally Posted by hoydyd View Post
EDIT: Nevermind on those questions above, I tried it out and it works perfectly and I think I understand it all, so basically its in a way similar to RegisterForEvent, but instead of an event on the event list, its whenever the UpdateHiddenState is called, right? (And you can do code before the function call) Also, in the original UpdateHiddenState(), it calls the SetHidden(value) function right? otherwise the second method (HookReticleSetHidden) wouldnt work. is that correct?
Yes, correct.


Inside UpdateHiddenState the SetHidden of that control is called based on GetUnitDisguiseState("player") and GetUnitStealthState("player")

function RETICLE:UpdateHiddenState() is a Lua shortcut for function RETICLE.UpdateHiddenState(self)

In Lua nearly everything is a variable. Including function names. Replacing/Overwritting a function is just assigning a new nameless function to a named table member/variable.
The overwritting takes place in the moment you do the assignment.
Putting the code into a function has two effects:
1. The scope of the "backup" variable is limited. So you know who can and will call the base function only.
2. The assignment=replacement is delayed to the moment everything is initialized (e.g. your saved variable=addon settings)

Otherwise you may get unexpected nil value errors. Happened to me

edit 1:
Originally Posted by hoydyd View Post
Was using these handlers(?) the intended way for manipulating objects?
Well, controls are just controls. Like your addon, there is always some additional code doing something with them.
And for a lot classes/instances ZOS is so kind to give public access via those global variables like RETICLE, PLAYER_INVENTORY and so on.

Last edited by votan : 06/05/15 at 04:10 AM.
  Reply With Quote