Thread Tools Display Modes
10-28-10, 01:27 AM   #1
neverg
A Frostmaul Preserver
 
neverg's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 268
Different Frames same SetScript

I'm writing my own version of a Text Stats addon (fps, mem, etc...) and I wanted (and acomplished) to display different tooltips when you hover over specific text strings (frames).

When setting some scripts, some are the same for the various frames. I did this for 3 frames:

lua Code:
  1. self.lf:SetScript("OnLeave", function() GameTooltip:Hide() end)
  2.     self.cf:SetScript("OnLeave", function() GameTooltip:Hide() end)
  3.     self.rf:SetScript("OnLeave", function() GameTooltip:Hide() end)

Is there any cleaner approach to this, Lua related? I don't think so, but just making sure.
__________________
My oUF Layout: oUF Lumen
  Reply With Quote
10-28-10, 02:11 AM   #2
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
Suppose you could store all the frames in a table and then traverse it and set the OnScript, but if we're only talking about three frames that will probably be less cleaner. :P
__________________
Oh, the simulated horror!
  Reply With Quote
10-28-10, 02:12 AM   #3
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
Code:
local function hideTooltip() GameTooltip:Hide() end

self.lf:SetScript("OnLeave",hideTooltip)
self.cf:SetScript("OnLeave",hideTooltip)
self.hf:SetScript("OnLeave",hideTooltip)
but your right, its pretty straight forward. both are negligble, just depends how you want to write.

in this way, you could at a print to the function like print("whoo hoo, take that tooltip!") and it would print on all 3 without having to add it 3 times, but meh what else could you do on leave :/
__________________
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
10-28-10, 02:14 AM   #4
neverg
A Frostmaul Preserver
 
neverg's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 268
Thanks guys. I Didn't think so, but needed to make sure.
__________________
My oUF Layout: oUF Lumen
  Reply With Quote
10-28-10, 08:38 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by neverg View Post
I'm writing my own version of a Text Stats addon (fps, mem, etc...) and I wanted (and acomplished) to display different tooltips when you hover over specific text strings (frames).

When setting some scripts, some are the same for the various frames. I did this for 3 frames:

lua Code:
  1. self.lf:SetScript("OnLeave", function() GameTooltip:Hide() end)
  2.     self.cf:SetScript("OnLeave", function() GameTooltip:Hide() end)
  3.     self.rf:SetScript("OnLeave", function() GameTooltip:Hide() end)

Is there any cleaner approach to this, Lua related? I don't think so, but just making sure.
Here, you are creating 3 functions in memory that are all the same. Instead, you can do this
lua Code:
  1. local function TooltipHide()
  2.     GameTooltip:Hide()
  3. end
  4.  
  5.     self.lf:SetScript("OnLeave", TooltipHide)
  6.     self.cf:SetScript("OnLeave", TooltipHide)
  7.     self.rf:SetScript("OnLeave", TooltipHide)

or this should work, too
lua Code:
  1. self.lf:SetScript("OnLeave", GameTooltip.Hide)
  2.     self.cf:SetScript("OnLeave", GameTooltip.Hide)
  3.     self.rf:SetScript("OnLeave", GameTooltip.Hide)
__________________
"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-29-10, 02:22 AM   #6
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
:O Seerah, you totally copied what i said... even our local functions names almost matched!
__________________
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
10-29-10, 06:33 AM   #7
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
or just GameTooltip_Hide()

(yes that's really a default function)
  Reply With Quote
10-29-10, 12:00 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by Xubera View Post
:O Seerah, you totally copied what i said... even our local functions names almost matched!
Wow... How did I miss that? I think I'll blame it on being sick.
__________________
"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

WoWInterface » Developer Discussions » Lua/XML Help » Different Frames same SetScript


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