View Single Post
11-24-13, 06:14 AM   #20
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Originally Posted by Uitat View Post
Lua Code:
  1. local aspect = CreateFrame("Frame", nil, UIParent)
  2.         aspect:RegisterEvent("PLAYER_ENTERING_WORLD")
  3.         aspect:SetScript("OnEvent", function(self, event)
  4.             UIParent:SetScale(0.6)  -- you can change the scale here but you will break the entire add-on --
  5.             aspect:UnregisterAllEvents()
  6.         print ("Your Resolution Scale has been changed to 0.6")
  7. end)

The indentation you're using there is a bit confusing. Disregard this if that's due to pasting it onto a forum. I'd indent it like this:
Lua Code:
  1. local aspect = CreateFrame("Frame", nil, UIParent)
  2. aspect:RegisterEvent("PLAYER_ENTERING_WORLD")
  3. aspect:SetScript(
  4.     "OnEvent",
  5.     function(self, event)
  6.         UIParent:SetScale(0.6)
  7.         self:UnregisterAllEvents()
  8.         print ("Your Resolution Scale has been changed to 0.6")
  9.     end
  10. )


I realize that my method of indenting complex function arguments is not everyone's cup of tea, though; so, alternatively:
Lua Code:
  1. local aspect = CreateFrame("Frame", nil, UIParent)
  2. aspect:RegisterEvent("PLAYER_ENTERING_WORLD")
  3. aspect:SetScript("OnEvent", function(self, event)
  4.         UIParent:SetScale(0.6)  -- you can change the scale here but you will break the entire add-on --
  5.         self:UnregisterAllEvents()
  6.         print ("Your Resolution Scale has been changed to 0.6")
  7. end)


Also, I changed aspect to self; I didn't see a reason to close on the aspect variable in that anonymous function when the frame reference is being passed into the function already.
  Reply With Quote