Much easier to just say "Marcus has N rage" or "Bob has N mana"... no need to worry about string manipulations and grammatical differences between languages that way.
Much easier to just say "Marcus has N rage" or "Bob has N mana"... no need to worry about string manipulations and grammatical differences between languages that way.
local f = CreateFrame("Frame",nil,UIParent)
f:SetFrameStrata("BACKGROUND")
f:SetWidth(128) -- Set these to whatever height/width is needed
f:SetHeight(64) -- for your Texture
local t = f:CreateTexture(nil,"BACKGROUND")
t:SetTexture("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Factions.blp")
t:SetAllPoints(f)
f.texture = t
frame = CreateFrame("Frame"); -- frame created, OnLoad handler called
frame:SetScript("OnLoad", function() print("Frame loaded") end); -- never called
local power = UnitPower("player" [, type]);
local name = UnitName("player")
local possessiveName = "";
if strsub(name, -1) == "s" then
possessiveName = name .. "'" -- Marcus' rage is whatever
else
possessiveName = name .. "'s" -- Bob's mana is whatever
end
local frame = CreateFrame("FRAME",nil,UIParent);
frame:RegisterEvent("UnitPower");
local function eventHandler(self, event, ...)
print("UnitPower" .. event);
end
frame:SetScript("OnEvent", eventHandler);
it still doesn't show anything and theres an error on line 25 for some reason.
In an API reference like wowwiki, square brackets are used to indicate paramters which are optional. So, in the above, "type" is an optional parameter when calling the UnitPower function. You don't leave the brackets in when you actually use the function. Either you call it with only the required first paramter:
local power = UnitPower("player")
^ This returns the amount of whatever kind of power is currently displayed on the player's power bar the player has.
Or you call it with the optional second parameter too:
local power = UnitPower("player", "MANA")
^ This returns the amount of mana the player has, even if mana isn't the currently displayed power time. This is primarily useful for druids, as it means that you don't need a "druid mana" addon to guess at how much mana you have while you're currently using rage or energy in a feral form.
local f = CreateFrame("Frame",nil,UIParent)
f:SetFrameStrata("BACKGROUND")
f:SetWidth(128) -- Set these to whatever height/width is needed
f:SetHeight(64) -- for your Texture
local t = f:CreateTexture(nil,"BACKGROUND")
t:SetTexture("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Factions.blp")
t:SetAllPoints(f)
f.texture = t
f:SetPoint("CENTER",0,0)
f:Show()
Button:SetTextFontObject("GameFontNormal")
MyFrame:SetMovable(true)
MyFrame:EnableMouse(true)
MyFrame:SetScript("OnMouseDown",function()
MyFrame:StartMoving()
end)
MyFrame:SetScript("OnMouseUp",function()
MyFrame:StopMovingOrSizing()
end)
frame:SetScript("handler",function(UnitPower) end)
frame = CreateFrame("Frame"); -- frame created, OnLoad handler called
frame:SetScript("OnLoad", function() print("Frame loaded") end); -- never called
local power = UnitPower("player")
local name = UnitName("player")
local possessiveName = "";
if strsub(name, -1) == "s" then
possessiveName = name .. "'" -- Marcus' rage is whatever
else
possessiveName = name .. "'s" -- Bob's mana is whatever
end
local frame = CreateFrame("FRAME",nil,UIParent);
frame:RegisterEvent("UnitPower");
local function eventHandler(self, event, ...)
print("UnitPower" .. event);
end
frame:SetScript("OnEvent", eventHandler);
alright i made those changes and now it comes up with a new error.
line 14: attempt to index global 'Button' (a nil value)
another thing:
t:SetTexture("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Factions.blp")
what can i change this to or where do i find out what i can change it to.
Line 14 is wrong because you've never defined "Button" anywhere. You also haven't created any button-type frames, so your frame ("f") doesn't have a "SetTextFontObject" method. Either supply "Button" as the first argument to your CreateFrame instead of "Frame" and change line 14 to call that method on "f", or create a font string yourself (the way you created a texture) and use :SetFontObject on it.
As for the :SetTexture call you asked about, you can change it to anything you want. Either use the Blizzard UI kit to extract all of the textures from the default UI and look for something you want to use (you may need to use a BLP converter to convert them to TGA or PNG images), or create your own texture, put it in your addon's folder, and use the path to it.
alright i made thoses changes and took out the texture and made it " (nil,"BACKGROUND") " also did f:SetFontObject. i have also moved some of the stuff around. Now on line 21 (old 16 ) it's giving me a function argument near 'f'. i changed the "Myframe" to the frame 'F' which is my frame so what am i missing
this is what it looks like now:
frame = CreateFrame("Frame"); -- frame created, OnLoad handler called
frame:SetScript("OnLoad", function() print("Frame loaded") end); -- never called
frame:SetScript("handler",function(UnitPower) end)
local f = CreateFrame("Frame",nil,UIParent)
f:SetFrameStrata("BACKGROUND")
f:SetWidth(128) -- Set these to whatever height/width is needed
f:SetHeight(64) -- for your Texture
local t = f:CreateTexture(nil,"BACKGROUND")
t:SetTexture(nil,"BACKGROUND")
t:SetAllPoints(f)
f.texture = t
f:SetPoint("CENTER",0,0)
f:Show()
f:SetFontObject
f:SetMovable(true)
f:EnableMouse(true)
f:SetScript("OnMouseDown",function()
f:StartMoving()
end)
f:SetScript("OnMouseUp",function()
f:StopMovingOrSizing()
end)
local power = UnitPower("player")
local name = UnitName("player")
local possessiveName = "";
if strsub(name, -1) == "s" then
possessiveName = name .. "'" -- Marcus' rage is whatever
else
possessiveName = name .. "'s" -- Bob's mana is whatever
end
local frame = CreateFrame("FRAME",nil,UIParent);
frame:RegisterEvent("UnitPower");
local function eventHandler(self, event, ...)
print("UnitPower" .. event);
end
frame:SetScript("OnEvent", eventHandler);
This is never called because frames created in Lua are "loaded" at the time you use CreateFrame, so by the time you add the OnLoad script, the frame is already loaded. If you need to do one-time initialization stuff, register for an event like PLAYER_LOGIN and do it there.
This tells WoW to set a script to be called on the "handler" pseudo-event that accepts one parameter "UnitPower" and does nothing with it. This doesn't make any sense, won't do anything, and it almost certainly not what you wanted to do. What are you trying to do with this line?
Lines 1-4:
All of these are unnecessary, actually. They don't do anything, are full of syntax errors, and aren't used anywhere else in your code. Just delete them.
Line 12:
t:SetTexture(nil, "BACKGROUND")
There is no second parameter to :SetTexture like this; you already specified the frame strata when you supplied "BACKGROUND" as the second parameter to :CreateTexture. If you don't have a texture file to set, you don't need to call :SetTexture at all, or even create a texture.
Line 19:
f:SetFontObject
As Torhal already pointed out, you're calling a method without giving it any parameters. Even if :SetFontObject worked with no parameters (it doesn't) you still need to include parentheses; otherwise Lua assumes that the next thing it sees is supposed to be the parameter, but since the next thing it sees is another call to a frame method, it gives you an error.
Additionally, frames do not have a :SetFontObject method. Either create your frame (Line 1) as a "Button" instead of a "Frame", or add a font string:
local text = f:CreateFontString(nil, "OVERLAY"[B], "GameFontNormal"[/B])
text:SetPoint("CENTER", f, "CENTER", 0, 0)
text:SetText("Hello World!")
Note that I bolded the third parameter to :CreateFontString. You can just set the font object this way when creating a font string, or you can call :CreateFontString without the third parameter, and call :SetFontObject on the font string later.
Lines 30-37:
local power = UnitPower("player")
local name = UnitName("player")
local possessiveName = "";
if strsub(name, -1) == "s" then
possessiveName = name .. "'" -- Marcus' rage is whatever
else
possessiveName = name .. "'s" -- Bob's mana is whatever
end
While there's nothing syntactically wrong with this code, since it is in the file scope, it will only be executed once when your addon loads, and the values will never be updated.
Lines 37-45:
local frame = CreateFrame("FRAME",nil,UIParent)
frame:RegisterEvent("UnitPower")
local function eventHandler(self, event, ...)
print("UnitPower" .. event)
end
frame:SetScript("OnEvent", eventHandler)
There is no event "UnitPower" so your event handler will never be called. You actually need to register a bunch of events to find out when someone's mana, rage, energy, or runic power changes.
You also don't need to create a second frame to handle events. Just register events and set your OnEvent handler directly on your main frame ("f").
See http://paste.wowace.com/518/ for a revised version of your code without the unnecessary stuff and syntax errors.
local power = UnitPower("player")
local name = UnitName("player")
local possessiveName = "";
if strsub(name, -1) == "s" then
possessiveName = name .. "'" -- Marcus' rage is whatever
else
possessiveName = name .. "'s" -- Bob's mana is whatever
end
While there's nothing syntactically wrong with this code, since it is in the file scope, it will only be executed once when your addon loads, and the values will never be updated.
That was mine and it was intended to be run when the text needed to be changed. :)
holy crap it works thanks to you guys babysitting me /bow /bow and Phanx... i can't come up with something witty to thank Phanx but damn. This is beginning to really make more sense.
there were a few errors in the paste but i found them and fixed them. which resulted in getting something on the screen that works pretty ok.
it seems any kind of regen that doesn't follow the 3 second rule doesn't get updated right away. Also the chat log gets spammed with " OnEvent: UNIT_(type)_POWER
so this is what it does and i'm pretty excited. i have a movable frame that says " player has power" in game font.
I took out line 56. so there is no more chat spam. i also tired changing the count to 0.01 which seems to be spot-on with blizzard's display.
Can i register an event to lock the frame with a slash command? i can't seem to find that answer on wow wiki. How else can i prevent the user from moving the frame when they don't want to? Can i limit it the drag command to when holding X button?
I'd also like to read something that will let me add a custom font or plug into another addon with fonts the user can choose from. Sorta like how you can with recount. i guess that would lead to me making a options menu, i think. Which i could put the unlock and lock into. What do you guys think is the best option?
Also before i go any further could i use anything with ace3 for any of this?
If you want GUI options (and I will eventually add them to Speedometer) I highly recommend Tekkub's tekKonfig libraries. Unlike AceGUI-3.0 each widget is standalone, and not a major pain in the ass to use without AceConfig-Dialog-3.0, so you don't have to embed ~225kb worth of libraries if all you want is a checkbox and a dropdown. Take a look at any of Tekkub's addons for examples of usage.
What is what about LibSharedMedia-3.0? If you want to offer font selection, you should use it. It's extremely simple to implement, adds almost no overhead, does not greatly increase your addon's download size, and provides great conveniences for both authors and users. It's also standalone, so it's not dependent on any Ace3 (or other) libraries.
Again, I'll point you at Speedometer for a simple example of LibSharedMedia-3.0 support.
What is what about LibSharedMedia-3.0? If you want to offer font selection, you should use it. It's extremely simple to implement, adds almost no overhead, does not greatly increase your addon's download size, and provides great conveniences for both authors and users. It's also standalone, so it's not dependent on any Ace3 (or other) libraries.
Again, I'll point you at Speedometer for a simple example of LibSharedMedia-3.0 support.
yeah sry i was looking at it and want to figure out what is was so i could make sense of it in the code.
I downloaded it and have it but i don't see anywhere in the folders on what to do with it or what i can do with it. Does Elkano have a site or something?
it still doesn't show anything and theres an error on line 25 for some reason.
Btw: I think there are CODE tags in this forum for posting code.
In an API reference like wowwiki, square brackets are used to indicate paramters which are optional. So, in the above, "type" is an optional parameter when calling the UnitPower function. You don't leave the brackets in when you actually use the function. Either you call it with only the required first paramter:
^ This returns the amount of whatever kind of power is currently displayed on the player's power bar the player has.
Or you call it with the optional second parameter too:
^ This returns the amount of mana the player has, even if mana isn't the currently displayed power time. This is primarily useful for druids, as it means that you don't need a "druid mana" addon to guess at how much mana you have while you're currently using rage or energy in a feral form.
alright i made those changes and now it comes up with a new error.
line 14: attempt to index global 'Button' (a nil value)
another thing:
t:SetTexture("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Factions.blp")
what can i change this to or where do i find out what i can change it to.
As for the :SetTexture call you asked about, you can change it to anything you want. Either use the Blizzard UI kit to extract all of the textures from the default UI and look for something you want to use (you may need to use a BLP converter to convert them to TGA or PNG images), or create your own texture, put it in your addon's folder, and use the path to it.
this is what it looks like now:
and should be
Line 1:
The way this is written you're creating a global variable named "frame". This should definitely be restricted to the local scope. Change to:
Line 2:
This is never called because frames created in Lua are "loaded" at the time you use CreateFrame, so by the time you add the OnLoad script, the frame is already loaded. If you need to do one-time initialization stuff, register for an event like PLAYER_LOGIN and do it there.
Line 4:
This tells WoW to set a script to be called on the "handler" pseudo-event that accepts one parameter "UnitPower" and does nothing with it. This doesn't make any sense, won't do anything, and it almost certainly not what you wanted to do. What are you trying to do with this line?
Lines 1-4:
All of these are unnecessary, actually. They don't do anything, are full of syntax errors, and aren't used anywhere else in your code. Just delete them.
Line 12:
There is no second parameter to :SetTexture like this; you already specified the frame strata when you supplied "BACKGROUND" as the second parameter to :CreateTexture. If you don't have a texture file to set, you don't need to call :SetTexture at all, or even create a texture.
Line 19:
As Torhal already pointed out, you're calling a method without giving it any parameters. Even if :SetFontObject worked with no parameters (it doesn't) you still need to include parentheses; otherwise Lua assumes that the next thing it sees is supposed to be the parameter, but since the next thing it sees is another call to a frame method, it gives you an error.
Additionally, frames do not have a :SetFontObject method. Either create your frame (Line 1) as a "Button" instead of a "Frame", or add a font string:
Note that I bolded the third parameter to :CreateFontString. You can just set the font object this way when creating a font string, or you can call :CreateFontString without the third parameter, and call :SetFontObject on the font string later.
Lines 30-37:
While there's nothing syntactically wrong with this code, since it is in the file scope, it will only be executed once when your addon loads, and the values will never be updated.
Lines 37-45:
There is no event "UnitPower" so your event handler will never be called. You actually need to register a bunch of events to find out when someone's mana, rage, energy, or runic power changes.
You also don't need to create a second frame to handle events. Just register events and set your OnEvent handler directly on your main frame ("f").
See http://paste.wowace.com/518/ for a revised version of your code without the unnecessary stuff and syntax errors.
That was mine and it was intended to be run when the text needed to be changed. :)
there were a few errors in the paste but i found them and fixed them. which resulted in getting something on the screen that works pretty ok.
it seems any kind of regen that doesn't follow the 3 second rule doesn't get updated right away. Also the chat log gets spammed with " OnEvent: UNIT_(type)_POWER
so this is what it does and i'm pretty excited. i have a movable frame that says " player has power" in game font.
so this is what it all looks like now http://paste.wowace.com/519/
If you want more frequent updates, you could update the value every OnUpdate... try this:
http://paste.wowace.com/520/
Can i register an event to lock the frame with a slash command? i can't seem to find that answer on wow wiki. How else can i prevent the user from moving the frame when they don't want to? Can i limit it the drag command to when holding X button?
I'd also like to read something that will let me add a custom font or plug into another addon with fonts the user can choose from. Sorta like how you can with recount. i guess that would lead to me making a options menu, i think. Which i could put the unlock and lock into. What do you guys think is the best option?
Also before i go any further could i use anything with ace3 for any of this?
For the lock/unlock and font selection functions, take a look at my addon Speedometer:
http://www.wowinterface.com/downloads/info8726-Speedometer.html
If you want GUI options (and I will eventually add them to Speedometer) I highly recommend Tekkub's tekKonfig libraries. Unlike AceGUI-3.0 each widget is standalone, and not a major pain in the ass to use without AceConfig-Dialog-3.0, so you don't have to embed ~225kb worth of libraries if all you want is a checkbox and a dropdown. Take a look at any of Tekkub's addons for examples of usage.
Again, I'll point you at Speedometer for a simple example of LibSharedMedia-3.0 support.
yeah sry i was looking at it and want to figure out what is was so i could make sense of it in the code.
I downloaded it and have it but i don't see anywhere in the folders on what to do with it or what i can do with it. Does Elkano have a site or something?