Thread Tools Display Modes
Prev Previous Post   Next Post Next
09-08-10, 09:08 PM   #1
Tiok
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 2
How to Deal With Loss of "this", "event", "arg#"

As we've been informed, the "this" "event" and "arg#" globals have vanished. I haven't seen a thread talking about what the impacts of these losses are, nor any commentary on how to deal them. I know I don't have all the answers yet, but hopefully we can collect them in this thread so that authors have a place to start with porting their addons.

Please, chime in with any problems/solutions you have come up with in regards to these disappearing globals!


Dealing with the Loss of "this"

"this" used to see a lot of use in XML-defined event handlers. You'll need to go through your XML files and replace all "this" references with "self" instead. This still works because any XML-defined event handler is called internally with the ":OnEvent()" format, which invisibly passes a "self" parameter into the code.

In any other function that used to rely on "this", you'll need to explicitly pass the "self" parameter from wherever the function is called. That means either using MyObj.MyFunc(self,...) or MyObj:MyFunc(...). The second invisibly passes MyObj in as the first parameter before the ... .


Dealing with the Loss of "event"

"event" used to be used in XML-defined event handlers as well, especially the OnEvent handler, where you could pass it on to different handler functions based on the name of the event. Although "event" is no longer a global, it IS present in the XML-defined OnEvent handler. The internal workings just pass it directly to OnEvent as a parameter now, rather than making it global. You actually don't have to worry about the change here, though you will have to make sure you're passing "event" through to any subsequent calls in your XML-defined handler that need it.


Dealing with the Loss of "arg#"
"arg#", the event argument globals, were used with almost every single event handler function. As with "event", these are now being passed to the XML-defined OnEvent handler as parameters instead of globals. Officially they're coming in as a "...", which you'll need to make sure you're passing along to any function calls that were making use of the global "arg#" variables before.
One handy trick to parse the "..." into useful parameters is this:
Code:
   local arg1, arg2, arg3 = ...
Which you can use at the start of any function that used the old global variables for a quick fix. It would probably be better to switch over to more meaningful names, though.


If you know the answer to any of these questions, or know any other problems and/or solutions related to these issues, let us know about it here!

Last edited by Tiok : 09-14-10 at 06:44 AM.
 
 

WoWInterface » AddOns, Compilations, Macros » Cataclysm Beta » How to Deal With Loss of "this", "event", "arg#"


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