Thread Tools Display Modes
10-12-10, 08:40 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
one more time on the this and arg stuff :)

I know i know we have gone over this before but one more time. I think i have the idea though. So in the code that will follow the mouse click is arg1 and a frame is this. These things have to be defined now via a local somthing = is how it works now right? How would you do that then? or can i ditch the arg1 being the mouse function and then define just the frame?

this is the code im attempting to change.

Code:
frame:SetScript("OnMouseDown",function(this,arg1) 
        if arg1=="LeftButton" and not self:AreBagsLocked() then 
            this:StartMoving() 
        end 
    end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
10-12-10, 08:47 PM   #2
Aznamir
A Fallenroot Satyr
 
Aznamir's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 26
If I remember correctly, you need to replace "this" with "self" and "arg1" with "button"
  Reply With Quote
10-12-10, 08:49 PM   #3
Maul
Ion Engines, Engage!
 
Maul's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 401
Script handlers define their own locals implicitly. They just exist, you can say. This list will help you understand which script handler define which locals for itself -

http://www.wowwiki.com/Widget_handlers

OnMouseDown defines the frame it belongs to as "self" and which button on the mouse was clicked -

OnMouseDown(self,button)
__________________

Twitter: @IonMaul | Windows Live: [email protected] | Google Talk: [email protected]
  Reply With Quote
10-12-10, 08:58 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You're mixing your "this"es and "self"s. Pick one.

/edit: I just posted this earlier - http://www.wowinterface.com/forums/s...ad.php?t=35401
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-13-10, 05:16 AM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by Aznamir View Post
If I remember correctly, you need to replace "this" with "self" and "arg1" with "button"
Defining function arguments is the exact same as choosing a name for a variable, it doesn't matter how you name it as long as it's a valid name.
__________________
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 : 10-13-10 at 05:19 AM.
  Reply With Quote
10-13-10, 08:50 AM   #6
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
When your frame picks up on the MouseDown event, it calls the function you have defined.

lua Code:
  1. local myFrame = CreateFrame("Frame")
  2. myFrame:SetScript("OnMouseDown", function(self, button)
  3.   print(self, button)
  4. end)

every OnMouseDown your frame captures will send 2 arguments. The frame that picked up the event (myFrame in this example), and which mouse button called the event (which mouse button was pushed down)

what you call these variables above is irrelevant.

myFrame:SetScript("OnMouseDown", function(bob, steve)
print(bob, steve)
end)
should have the same output as the code above.

The big change was that some code came out like

myFrame:SetScript("OnMouseDown", function()
print(self, button)
end)

because self, button, arg1 - arg13 were stored in the global environment. Now they are not, so its up to the programmer to make sure they define the variables.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » one more time on the this and arg stuff :)


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