Thread Tools Display Modes
11-12-10, 07:26 PM   #1
squiretoad
A Defias Bandit
Premium Member
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 3
With The Global "this:" Gone

Any number of addons have broken. One example is the very useful BugMeNot addon (which I'm trying to patch right now).

I've figured out workarounds for most of the "this:" uses in the BugMeNot.lua code, but not all of them. Any suggestions from others as to how they solved similar problems?

A message in another forum addressed this issue, but was damnably sketchy on how to solve the problem.


http://forums.worldofwarcraft.com/th...76430349&sid=1

They say "use self and pass it between functions." Yeah, right ... so someone tell me how to do that with BugMeNot.lua? Or Thottbot.lua? Or Dialect.lua? Because I cannot make "self" work ANYWHERE in any real world code.

Understand I was a pretty good programmer in my time, but never made the mental jump to OOP, so I'm still pretty shakey about all this stuff about objects, frames, etc.

For instance, I have BugMeNot running again (optimized quite a bit even) ... but am still getting errors when making changes on the popup GUI menu (where the code used "this:" numerous times).

function DropDownMenuItem_OnClick()
UIDropDownMenu_SetSelectedValue(this.owner, this.value);
PlaySound("igMainMenuOptionCheckBoxOn");
if (this.value == 0) then
--We clicked the first menu item. Enter code here to affect the rest of your mod.
elseif (this.value == 1) then
--We clicked the second menu item. Enter code here to affect the rest of your mod.
end
end

With every button, every text field, every checkbox being its own separate object, how the HELL can I identify what clicked? Who owns it? What the value was, or is?

Thanks in advance.
  Reply With Quote
11-12-10, 07:40 PM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Pass a reference to the object with DropDownMenuItem_OnClick. Example:
Code:
f = CreateFrame("MyNewFrame")
DropDownMenuItem_OnClick(f)
Then add a parmeter to the function and use it within the function:
Code:
function DropDownMenuItem_OnClick(self)
    UIDropDownMenu_SetSelectedValue(self.owner, self.value);
	PlaySound("igMainMenuOptionCheckBoxOn");
  if (self.value == 0) then
    --We clicked the first menu item. Enter code here to affect the rest of your mod.
  elseif (this.value == 1) then
    --We clicked the second menu item. Enter code here to affect the rest of your mod.
  end
end
[Edit]
LUA isn't OOP.
  Reply With Quote
11-13-10, 10:04 PM   #3
squiretoad
A Defias Bandit
Premium Member
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 3
Thanks for the (only) response. That's exactly what I did, and my code ended up looking exactly like yours.

Except I'm still getting UIDropDownMenu lua errors: "attempt to index local "frame" (a nil value). It's talking about self, of course.

self simply isn't bringing in a frame. And there's no simple "CreateFrame" function in this code: a hugely complicated .xml file is creating frames, buttons, text fields, the lot. Everything seems to have its own bloody name and frame.

Oh, and when you're not an OOP programmer, lua certainly DOES look object oriented. Oh sure, it's all just structures and pointers; I know that. But then so is OOP. I don't see any significant difference. But no matter.

My check buttons are working fine; it's the 3-selection drop-down menus that are triggering the errors. Almost there, but not quite.
  Reply With Quote
11-13-10, 10:46 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
Some of these addons aren't that easy to convert from the "this" style. You'd have to track down the root of every function call and modify it so the function gets the UI object it needs.

I can take a look into it, but I need to look at the full source code you have running to see where I can patch it up.

Btw, Lua is more of a programming framework that's injected into a host environment. It takes whatever form is needed to run. Lua can be OOP through creative use of tables and metatables. WoW's Widget API tries to push it more towards OOP using shared metatables.

Also note the WoW implementation is not multithreaded. Going into an infinite loop will cause WoW to freeze.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-13-10 at 10:56 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » With The Global "this:" Gone


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