Thread Tools Display Modes
02-28-13, 09:36 AM   #1
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Script to change certain settings on an addon?

Hi and thank you for reading this,

My problem is that I do not want to have multiple profiles and having to switch to each one depending upon the situation because I only want to change the position of the Party frames. It seems unnecessary to have two profiles when its only a small change and it is a big hassle to manage with all the scripts I am using in my UI. I don't want to go into the long story of why I need to do the following below if I can help it but what I want to know is the following:

Is it possible to create a script that changes a few settings in the Shadowed Unit Frame built in GUI menu without having to have two separate profiles?

I want to just simply change the position of the Party frame by changing the following options in the form of an OnUpdate script if possible. Else an OnClick script I could also work with.

in the Unit configuration list > Party > Party (tab) > under Manual Position:
Point = Top Left
Relative Point = Top Left
Y Offset = -5

in the Unit configuration list > Party > Party (tab):
Row Growth = Down


Thank you in advance. I have been looking in the lua files of the Shadowed Unit Frame addon folder but I am not sure what to look for and if I find it, how will I register in my addon folder (or KgPanel script page) that I need it to know where to find these variables? I hope that makes some sense, if not at least what I am asking for!)
  Reply With Quote
02-28-13, 09:52 AM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
You'd preferrably have to find the functions in Shadowed Unit Frame that apply the settings you want to change, then hook them using hooksecurefunc if possible so that your own functions are executed right afterwards.

You definitely shouldn't use OnUpdate for this. OnUpdate functions run every time a new frame is drawn, so at 60 frames per second, each OnUpdate function is run 60 times per second which is a burden on the processor. It should be reserved for timers and similar things.
  Reply With Quote
02-28-13, 10:34 AM   #3
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
I've been searching through the files and think I found something that might be needed but not sure what I'm looking at and do not know what to do with it so I think its best to give up.

I would have been happy if I could just find a script to change a unit frames Y Offset so that I do not need an entire new profile to just change the Target of Target frame's Y Offset up by 50 pixels. That would greatly make my workload a lot less :/
  Reply With Quote
02-28-13, 10:47 AM   #4
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Haleth View Post
You definitely shouldn't use OnUpdate for this. OnUpdate functions run every time a new frame is drawn, so at 60 frames per second, each OnUpdate function is run 60 times per second which is a burden on the processor. It should be reserved for timers and similar things.

This is sort of worrying because I am using many OnUpdate KgPanel scripts such as this:
Code:
if IsAddOnLoaded("Chatter") then
if LibStub("AceAddon-3.0"):GetAddon("Chatter").db:GetCurrentProfile() == "MayronUI" then
    self:Show()
else
    kgPanels:FetchFrame("chatB"):Show()
    Bazooka.db:SetProfile("MayronUI2")
    self:Hide()
end
end
I know this might be off topic but should I be worrying about this? If so what should I be doing instead?
  Reply With Quote
02-28-13, 11:31 AM   #5
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by Mayron View Post
This is sort of worrying because I am using many OnUpdate KgPanel scripts such as this:
[...]

I know this might be off topic but should I be worrying about this? If so what should I be doing instead?
Like said, frames run their OnUpdate script on every frame per second as long as the frame is shown.
One thing you can use if you absolutely must use Onupdate is what we like to call a "bucket timer". You use a variable that grows every frame, if the variable is more then the number of seconds between each bucket, you reset the variable and run a script.
For example: You want to run a script each second (for a simple clock panel)
OnLoad:
lua Code:
  1. self.elapsed = 0
OnUpdate:
lua Code:
  1. self.elapsed = self.elapsed + elapsed -- increment by time passed since last frame update
  2. if self.elapsed < 1 then return end -- has a second elapsed
  3. self.elapsed = 0 -- reset the timer
  4. self.text:SetFormattedText("%02d:%02d", GetGameTime())

Another or better thing you could do, is register for the correct event that you need, for example, PLAYER_LOGIN, which only triggers when you login:
OnLoad:
lua Code:
  1. self:RegisterEvent('PLAYER_LOGIN')
OnEvent
lua Code:
  1. -- Conditional checking on events is totally optional. I usually omit it when I only need to listen for one event.
  2. if event == 'PLAYER_LOGIN' then
  3.     -- do stuff
  4. end

Your example script could be converted to use events (ADDON_LOADED):
lua Code:
  1. if not IsAddOnLoaded("Chatter") then
  2.     self:RegisterEvent('ADDON_LOADED')
  3.     self:Hide()
  4. else
  5.     self:ConditionalShow()
  6. end
  7.  
  8. -- define a function so we dont have to paste the same code in the onevent box.
  9. function self:ConditionalShow()
  10.     if LibStub("AceAddon-3.0"):GetAddon("Chatter").db:GetCurrentProfile() == "MayronUI" then
  11.         self:Show()
  12.     else
  13.         kgPanels:FetchFrame("chatB"):Show()
  14.         Bazooka.db:SetProfile("MayronUI2")
  15.         self:Hide()
  16.     end
  17.     -- Chatter is loaded here so we dont have to listen to ADDON_LOADED anymore, clean up this frame
  18.     self:UnregisterEvent('ADDON_LOADED')
  19.     self:SetScript('OnEvent', nil)
  20.     self.ConditionalShow = nil
  21. end

OnEvent:
lua Code:
  1. if event == 'ADDON_LOADED' and arg1 == 'Chatter' then
  2.     self:ConditionalShow() 
  3. end
My example triggers when Chatter is being loaded as well, without running every frame.

EDIT: I realised you can check if a user has an AddOn enabled or if it is load on demand: GetAddOnInfo

New logic should then be:
Code:
if user has AddOn enabled
    If addon is not yet loaded, 
        register for ADDON_LOADED
        set onevent handler for ADDON_LOADED here
    else
         run specific code for that addon
    end
end
Happy coding

Last edited by ravagernl : 02-28-13 at 12:11 PM.
  Reply With Quote
02-28-13, 12:05 PM   #6
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
wow this looks really promising! That does not even look too difficult (because I don't know a lot about lua programming myself) so hopefully I can try to apply this to many other OnUpdate scripts I have and hopefully improve my frame rate

Thank you. Wish I was better at lua script. It gets me depressed lol


When I try your script I keep getting the following error message:

attempt to call method 'ConditionalShow' (a nil value)

and when I put "local" in front of this line:
Code:
function self:ConditionalShow()
it just says:

"(" expected near ":"

so not sure what's wrong there

Last edited by Mayron : 02-28-13 at 12:15 PM.
  Reply With Quote
02-28-13, 03:27 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The problem is that in this code:
Code:
if not IsAddOnLoaded("Chatter") then
    self:RegisterEvent("ADDON_LOADED")
    self:Hide()
else
    self:ConditionalShow()
end

-- define a function so we dont have to paste the same code in the onevent box.
function self:ConditionalShow()
    if LibStub("AceAddon-3.0"):GetAddon("Chatter").db:GetCurrentProfile() == "MayronUI" then
        self:Show()
    else
        kgPanels:FetchFrame("chatB"):Show()
        Bazooka.db:SetProfile("MayronUI2")
        self:Hide()
    end
    -- Chatter is loaded here so we dont have to listen to ADDON_LOADED anymore, clean up this frame
    self:UnregisterEvent("ADDON_LOADED")
    self:SetScript("OnEvent", nil)
    self.ConditionalShow = nil
end
The "ConditionalShow" method is not yet defined when you try to call it in the first block. You need to define the method first, and then check for Chatter and call it. Just swap the order of the blocks:
Code:
-- define a function so we dont have to paste the same code in the onevent box.
function self:ConditionalShow()
    if LibStub("AceAddon-3.0"):GetAddon("Chatter").db:GetCurrentProfile() == "MayronUI" then
        self:Show()
    else
        kgPanels:FetchFrame("chatB"):Show()
        Bazooka.db:SetProfile("MayronUI2")
        self:Hide()
    end
    -- Chatter is loaded here so we dont have to listen to ADDON_LOADED anymore, clean up this frame
    self:UnregisterEvent("ADDON_LOADED")
    self:SetScript("OnEvent", nil)
    self.ConditionalShow = nil
end

if not IsAddOnLoaded("Chatter") then
    self:RegisterEvent("ADDON_LOADED")
    self:Hide()
else
    self:ConditionalShow()
end
Also, (mainly directed at ravagernl) don't mix single- and double-quotes for defining strings. Pick one style and stick with it. I'd suggest double-quotes, since you'll want apostrophes in your strings more often than you'll want quotation marks, but either one is fine. Just don't use one on one line, and the other on the next line. It's like mixing tabs and spaces for indentation in the same file.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
02-28-13, 04:16 PM   #8
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
I coded it without testing, directly in the quick reply box so that's why the function was defined in the wrong place. And everything that has single quotes was written by me, I copy pasta'd the rest

Also, you can't make functions defined in a table local, besides, "self" already is a local variable in the script handler. That is why the lua interpreter is telling you about "(" expected near ":"
See "Method calling conventions": http://lua-users.org/wiki/ObjectOrientationTutorial

Last edited by ravagernl : 02-28-13 at 04:25 PM. Reason: False info given
  Reply With Quote
02-28-13, 05:30 PM   #9
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Usually even I would have noticed that. That makes complete sense and I will try this out soon when I've finished with some other coding work that is slightly simpler but I still have managed to get stuck on it lol
Fortunately this has been a nice learning experience for me

Thank you so much everyone, you all have been a great help to me!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Script to change certain settings on an addon?

Thread Tools
Display Modes

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