Thread Tools Display Modes
01-10-10, 02:03 PM   #21
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
*hint* .. you want to test for the aura/buff when the event occurs

If we walk through your code it may help you.
1. Addon is loaded and creates a frame to handle events.
2. Addon registers the UNIT_AURA event to watch for
4. Addon checks to see if Righteous Fury buff is active on player
5. hasrf variable defined but not initialised and thus treated as false
6 to 13 define event handler to handle events being watched ( but not executed at this time )
14. We can now activate the event watching by telling the frame what function to run when handling its watched events.

The addon will now only use the event handler function when UNIT_AURA is triggered. Thus at present your test for Righteous Fury happens once at the beginning but is never tested again.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
01-10-10, 02:34 PM   #22
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Originally Posted by Xrystal View Post
*hint* .. you want to test for the aura/buff when the event occurs

If we walk through your code it may help you.
1. Addon is loaded and creates a frame to handle events.
2. Addon registers the UNIT_AURA event to watch for
4. Addon checks to see if Righteous Fury buff is active on player
5. hasrf variable defined but not initialised and thus treated as false
6 to 13 define event handler to handle events being watched ( but not executed at this time )
14. We can now activate the event watching by telling the frame what function to run when handling its watched events.

The addon will now only use the event handler function when UNIT_AURA is triggered. Thus at present your test for Righteous Fury happens once at the beginning but is never tested again.
haha still cant get it, but think its something to change at 5. then? Maybe set like hasrf('Player') or something? Cant figure it out, more help xD
  Reply With Quote
01-10-10, 02:42 PM   #23
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by opismahname View Post
haha still cant get it, but think its something to change at 5. then? Maybe set like hasrf('Player') or something? Cant figure it out, more help xD
hasrf wasn't supposed to be a function. right now, it's only evaluated before you set the event handler. What you want to do is check it you have the righteous fury buff active on you every time you gain or loose an aura.

The first return value of UnitBuff will give you:
  • The name of the buff as a string when it is active.
  • nil, when the buff is not active.
A string will always evaluate to true. nil will evaluate as false.
  Reply With Quote
01-10-10, 02:46 PM   #24
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
Okay, another clue is if we run through your event handler with your exisitng code set up.

1. Addon Loaded.
2. Variable active is set if Righteous Fury is active on the player when first loaded otherwise it is treated as false. Lets assume you do not have the buff at this time so active is false.
3. Variable hasrf is assumed false at this point as no value assigned to it.
4. Addon Registers UNIT_AURA event and is ready to process the event handling function when the event occurs.
3. You the player activate your Righteous Fury buff and the event is triggered.

Now, here's the event handling function being processed. As we have set up above as an example active is false and hasrf is false.

4. Because hasrf is false and active is false the function ends as neither statements are valid.

For the message to trigger you need active to be true and with your code that will only happen if the buff is already active when you first log in.

So what you need to do is carry out the test inside the event handling function so that when you receive the buff or lose the buff it will be able to handle it properly as you are testing for it when the event happens and not before.

So, move line 4 of that code example so that it appears inside the function. I'll let you figure out the correct place to put it for yourself
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
01-10-10, 02:49 PM   #25
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Originally Posted by mrruben5 View Post
hasrf wasn't supposed to be a function. right now, it's only evaluated before you set the event handler. What you want to do is check it you have the righteous fury buff active on you every time you gain or loose an aura.

The first return value of UnitBuff will give you:
  • The name of the buff as a string when it is active.
  • nil, when the buff is not active.
A string will always evaluate to true. nil will evaluate as false.
And how do i make the name of the buff to a string when its active, and to a nil when its not active?

It seems to be hopless for me to begin making addons, this is to hard :S
  Reply With Quote
01-10-10, 03:01 PM   #26
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by opismahname View Post
And how do i make the name of the buff to a string when its active, and to a nil when its not active?
The answer is in what you quoted. The line:
Code:
local active = UnitBuff('player', 'Righteous Fury')
makes active "true" if you have RF on, and "false" if not. Therefore, you need to put that line inside the function, so that the addon checks for whether you have the buff every time the function runs.
  Reply With Quote
01-10-10, 03:05 PM   #27
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by opismahname View Post
It seems to be hopless for me to begin making addons, this is to hard :S
The difference between people who learn how to do it and people who don't is whether they are willing to put up with the learning curve. It's worse for you because you've never coded in any language before; but if you continue the way you are you'll eventually be able to do stuff like this little project without even thinking about it.
  Reply With Quote
01-10-10, 03:21 PM   #28
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by opismahname View Post
And how do i make the name of the buff to a string when its active, and to a nil when its not active?

It seems to be hopless for me to begin making addons, this is to hard :S
A string is a variable wich holds a number of characters between two symbols, wich in lua, and many other programming languages, are denoted by quotes. Therefore, "test" and 'test' are both strings. When you are using a control syntax, like if then end, the variable get's converted to a boolean. A boolean means: true, or false. Power on, power off.
Code:
a = 'test'
b = "test"
'print a' will put test in your chatframe. 'print b' will do the same. However, when you pass it to a control mechanism, it gets converted to a boolean:

'print (a == b)' will give you the number 1 in the chat frame. Why? Because a chat frame or console can only accept strings to display.

Last edited by ravagernl : 01-10-10 at 03:24 PM.
  Reply With Quote
01-10-10, 03:22 PM   #29
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Then i guess it would be like this...

Code:
local frame = CreateFrame("FRAME", "RFFrame");
frame:RegisterEvent("UNIT_AURA");
local function eventHandler(self, event, ...)
local active = UnitBuff('player', 'Righteous Fury')
local hasrf
local function eventHandler(self, event, ...)
local active = UnitBuff('player', 'Righteous Fury')
if not hasrf and active then
    hasrf = true
    print('Rigtheous Fury has been activated')
elseif hasrf and not active then
    hasrf = false
    end
end
frame:SetScript("OnEvent", eventHandler);
Or does it matter where in the function the line is placed?

EDIT: Saw that it's 2 local active now, is it just UnitBuff('player', 'Righteous Fury') i should put in the function? :O
  Reply With Quote
01-10-10, 03:28 PM   #30
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
It does matter where in the function you place it, because it needs to be evaluated before your "if" statement (since the "if" statement checks its value). You happen to have done this already, so it's correct as it is, except:

1. You should not have two different "local active....." lines or two different "local function eventHandler...." lines.
2. You also still need to keep the "local hasrf" line *above* the beginning of the eventHandler code (we can get into why that is later, once you get the code working).
  Reply With Quote
01-10-10, 03:33 PM   #31
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
You need to define those two variables named hasrf and active before you define the function. Also, you only need to define the function once.

Code:
local frame = CreateFrame("Frame", "RFFrame")
frame:RegisterEvent("UNIT_AURA")

local active = UnitBuff('player', 'Righteous Fury')
local hasrf = (active) -- will contain a boolean, true if 'active' contains a string, and false if 'active' contains nothing(nil)

local function eventHandler(self, event, ...)
    active = UnitBuff('player', 'Righteous Fury')
    if not hasrf and active then
        hasrf = true
        print('Rigtheous Fury has been activated')
    elseif hasrf and not active then
        hasrf = false
    end
end
frame:SetScript("OnEvent", eventHandler)
I've removed the word local inside the function, the word local assigns a variable to a namespace. But that's something we could discuss later.

Last edited by ravagernl : 01-10-10 at 03:40 PM.
  Reply With Quote
01-10-10, 03:37 PM   #32
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Code:
   1.
      local frame = CreateFrame("FRAME", "RFFrame");
   2.
      frame:RegisterEvent("UNIT_AURA");
   4.
      local active = UnitBuff('player', 'Righteous Fury')
   5.
      local hasrf
   6.
      local function eventHandler(self, event, ...)

   7.
      local active = UnitBuff('player', 'Righteous Fury')
   8.
          if not hasrf and active then
   9.
              hasrf = true
   10.
              print('Rigtheous Fury has been activated')
  11.
          elseif hasrf and not active then
  12.
              hasrf = false
  13.
          end
  14.
      end
  15.
      frame:SetScript("OnEvent", eventHandler);
Is this right then?
  Reply With Quote
01-10-10, 03:42 PM   #33
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by opismahname View Post
Code:
[...]
Is this right then?
Look at my post before yours.
  Reply With Quote
01-10-10, 04:01 PM   #34
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Since there's been working code posted now, I may as well also. Hopefully the comments will be useful as opposed to confusing.

lua Code:
  1. local frame = CreateFrame("Frame") --Create the object that will watch for events.
  2. frame:RegisterEvent("UNIT_AURA") --Tell it to watch for buffs getting applied/fading
  3.  
  4. local hasrf = UnitBuff('player', 'Righteous Fury') --Create a variable that stores whether we had RF the last time we checked for it
  5.  
  6. local function eventHandler(self, event, ...) --From here until "--end function" will be code that gets run every time a buff gets added/fades
  7.     if ... ~= "player" then return end --Stop if the event didn't fire for the player.
  8.     local active = UnitBuff('player', 'Righteous Fury') --Check whether we have RF
  9.     if active and not hasrf then --Check whether we have RF *and* we did not have it last time.
  10.         print('Rigtheous Fury has been activated') --Print line
  11.     end --end if
  12.     hasrf = active --Store whether RF was active this time, so that we can check it later
  13. end --End function
  14. frame:SetScript("OnEvent", eventHandler) --Tell "frame" to run eventHandler every time a buff gets added or fades
  Reply With Quote
01-11-10, 11:59 AM   #35
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Hehe thanks! Will check if the codes is working now... Just a question, do you just know what will be putted inside the local function or are you testing many things and see if it works? Because i dont know how you can do this... x)
  Reply With Quote
01-11-10, 12:06 PM   #36
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
On the wowwiki website you can find lots of different functions and events you can use to do different things. Some are simple whilst others are more complex. Relatively speaking of course to each persons level of knowledge.

Start simple and work your way up. The addon you are working on now can pretty much be adjusted for any Aura that is triggered, or even all auras. Change the chat window display to a big message in the middle of the screen.

Find a small addon that does what you like and then see if you can figure out how it does it and then see if you can make adjustments. An unmoveable frame that you want to move ? Find out how you can do it and make the change.

There are alot of things you can do once you get started. You've made the first step, now carry on down the road.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
01-11-10, 12:22 PM   #37
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
One thing. It's "Righteous Fury", not "Rigtheous Fury".

__________________
Never be satisfied with satisfactory.
  Reply With Quote
01-11-10, 12:42 PM   #38
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Originally Posted by Xrystal View Post
On the wowwiki website you can find lots of different functions and events you can use to do different things. Some are simple whilst others are more complex. Relatively speaking of course to each persons level of knowledge.

Start simple and work your way up. The addon you are working on now can pretty much be adjusted for any Aura that is triggered, or even all auras. Change the chat window display to a big message in the middle of the screen.

Find a small addon that does what you like and then see if you can figure out how it does it and then see if you can make adjustments. An unmoveable frame that you want to move ? Find out how you can do it and make the change.

There are alot of things you can do once you get started. You've made the first step, now carry on down the road.
What's the code for making this text in the middle of the screen? And do i need to do something with a xml file or something to do it?
  Reply With Quote
01-11-10, 12:50 PM   #39
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Originally Posted by opismahname View Post
What's the code for making this text in the middle of the screen? And do i need to do something with a xml file or something to do it?
You have 2 options.

You can make the font string yourself,

http://www.wowwiki.com/UIOBJECT_FontString
http://bit.ly/6Cr9a3 (list of Fontstring documents)

or you can use Blizzard's pre-setup: (RaidWarning.lua http://wowcompares.com/33010958/Fram...aidWarning.lua)

Code:
RaidNotice_AddMessage(RaidWarningFrame, "TEXT HERE", ChatTypeInfo[chattype])
"chattype" can be "RAID_WARNING" (prominent) or "RAID_BOSS_EMOTE" (subtle)

Hope this helps.
__________________
Never be satisfied with satisfactory.
  Reply With Quote
01-11-10, 12:59 PM   #40
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Originally Posted by Cralor View Post
You have 2 options.

You can make the font string yourself,

http://www.wowwiki.com/UIOBJECT_FontString
http://bit.ly/6Cr9a3 (list of Fontstring documents)

or you can use Blizzard's pre-setup: (RaidWarning.lua http://wowcompares.com/33010958/Fram...aidWarning.lua)

Code:
RaidNotice_AddMessage(RaidWarningFrame, "TEXT HERE", ChatTypeInfo[chattype])
"chattype" can be "RAID_WARNING" (prominent) or "RAID_BOSS_EMOTE" (subtle)

Hope this helps.
Do i need to create a whole new code or can i just do something like this?:

Code:
local frame = CreateFrame("Frame", "RFFrame")
frame:RegisterEvent("UNIT_AURA")

local active = UnitBuff('player', 'Righteous Fury')
local hasrf = (active) -- will contain a boolean, true if 'active' contains a string, and false if 'active' contains nothing(nil)

local function eventHandler(self, event, ...)
    active = UnitBuff('player', 'Righteous Fury')
    if not hasrf and active then
        hasrf = true
        RaidNotice_AddMessage(RaidWarningFrame, "Threat Buff Activated", ChatTypeInfo[RAID_WARNING])
    elseif hasrf and not active then
        hasrf = false
    end
end
frame:SetScript("OnEvent", eventHandler)
Think this will not work, but just asking if i can do something with my old addon to replace the print function to a message in the middle.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » First Addon - need help


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