View Single Post
04/17/14, 08:07 PM   #14
Total-Khaos
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 6
Originally Posted by Seerah View Post
  1. Always use events instead of an OnUpdate script if events are available.

  2. If you must use an OnUpdate script, then buffer that OnUpdate script so that it's not called on each and every frame draw (if you have 50fps, that's 50 times per second your function is trying to run).

  3. Always make your variables/functions/etc. local unless you must have them in the global scope. If they have to be global, then give them unique names. AutoHide, menu1, etc. are not unique. If another developer slips and leaks a variable named menu1 into the global scope, the two variables will overwrite one another. Keeping them local avoids this problem, and is better for performance.

  4. Don't use string.format if you're not actually doing any formatting. Just use :SetText("text"). It'll save you a function call.

  5. The backdrop and label are children of your myAddonUI control. As I explained earlier in this thread, they will inherit visibility from their parent. Don't call :SetHidden() for these. Just call :SetHidden() on the parent frame. And then you can leave the :SetMouseEnabled() call out of it. Because it'll be hidden. This will save you two function calls here.
I'm just learning myself; however, I noticed that if I just set my parent to hidden, it doesn't reappear when it should. I hit ESC to open the game menu for example, the parent hides as expected, but never reappears when the ESC game menu is closed.

Code:
	if not menu1 or not menu2 or not menu3 or not menu4
	then
		myAddonUI:SetHidden(true)
	else
		myAddonUI:SetHidden(false)
	end
This is why I opted to hide all the children instead.
  Reply With Quote