Kerecha, you code isn't quite optimal, here is an improvement.
You don't want to call functions you have already defined. Here are minor changes to your code:
if not UnitIsDeadOrGhost(unit) then
if UnitPowerType(unit) == 0 then
local max = MaxPower(unit)
local cur = Power(unit)
if max > 0 and cur ~= max then
return "%s%%",Percent(cur,max)
else
return Short(max)
end
end
end
local s = Status(unit)
if s then
return s
end
local cur, max = HP(unit), MaxHP(unit)
if UnitIsFriend(unit,"player") then
local miss = max - cur
if miss ~= 0 then
return "-%d",miss
else
return Short(max)
end
else
return "%s/%s",Short(cur,true),Short(max,true)
end
Kerecha, you code isn't quite optimal, here is an improvement.
You don't want to call functions you have already defined. Here are minor changes to your code:
if not UnitIsDeadOrGhost(unit) then
if UnitPowerType(unit) == 0 then
local max = MaxPower(unit)
local cur = Power(unit)
if max > 0 and cur ~= max then
return "%s%%",Percent(cur,max)
else
return Short(max)
end
end
end
local s = Status(unit)
if s then
return s
end
local cur, max = HP(unit), MaxHP(unit)
if UnitIsFriend(unit,"player") then
local miss = max - cur
if miss ~= 0 then
return "-%d",miss
else
return Short(max)
end
else
return "%s/%s",Short(cur,true),Short(max,true)
end
Sweet, another minor lesson to add to it all (i dun know know anything about lua, just working with logic here)
guildName, guildRankName, guildRankIndex = GetGuildInfo(unit)
return "|cffffffff<%s>|r",guildName or ""
Basically you need to check if the function returns nothing. You could do that with an if statement, or you can do what I did above. If guildName is assigned something (by a player in a guild) then that will be displayed. If nothing is assigned to guildName then instead of passing nil to the format function it will pass an empty string, which should stop the error.
guildName, guildRankName, guildRankIndex = GetGuildInfo(unit)
return "|cffffffff<%s>|r",guildName or ""
Basically you need to check if the function returns nothing. You could do that with an if statement, or you can do what I did above. If guildName is assigned something (by a player in a guild) then that will be displayed. If nothing is assigned to guildName then instead of passing nil to the format function it will pass an empty string, which should stop the error.
That works, but i need to change the "|cffffffff<%s>|r" to hide the <> when there is no value displayed but im still to figure out the Angle stuff (still have no grasp of the formating)
Like I said before you can control what is returned with an if-else block. I didn't see the angle brackets. This is essentially the same thing, check to make sure guildName has a value and return your formatting and the name or an empty string to have a blank text.
guildName, guildRankName, guildRankIndex = GetGuildInfo(unit)
if guildName then
return "|cffffffff<%s>|r",guildName
else
return ""
end
Edit: If you don't need the other returns (rank and rank index), you don't need to include them on the first line.
guildName = GetGuildInfo(unit)
will still give you the name and save less information in memory (small amount sure, but every little bit helps :))
local guildName = GetGuildInfo(unit)
if guildName then
return "|cffffffff<%s>|r",guildName
end
Really should do local on your variables unless you actually want it saved between runs. There's no reason to capture the other returns
And Satrina, no point in returning "" for nothing. Not returning anything handles that for you. It's not wrong or anything, just makes the code a bit longer for no real benefit.
local guildName = GetGuildInfo(unit)
if guildName then
return "|cffffffff<%s>|r",guildName
end
Really should do local on your variables unless you actually want it saved between runs. There's no reason to capture the other returns
And Satrina, no point in returning "" for nothing. Not returning anything handles that for you. It's not wrong or anything, just makes the code a bit longer for no real benefit.
Will give that a shot then (im still shotting blind here).
But i think i have gotten most of the texts working now (with some minor changes).
While looking through the API page for WoW at wowwiki.com, I noticed that there is a function UnitPower(unit,[type]) that seems to be identical to the function Power(unit,[type]) offered by Lua Text.
Given the context of much of Shefki's admonitions ("zomg! redundant calls!"), I'm clearly missing something.
What gives?
(BTW, pqee, I was looking over there to find the pet owner name function, and couldn't see one.)
Faction and PvP: A for alliance and H for horde, colored based on PvP flagg (about the same as the default names are colored). My faction green for pvp on, blue for pvp off. Opposite faction depends on my pvp state (yellow if im off and they are on, red if both are on and blue if both are off) Currently i only play alliance and tag might reflect that (i haven't made the tag myself so i don't really know)
While looking through the API page for WoW at wowwiki.com, I noticed that there is a function UnitPower(unit,[type]) that seems to be identical to the function Power(unit,[type]) offered by Lua Text.
Given the context of much of Shefki's admonitions ("zomg! redundant calls!"), I'm clearly missing something.
What gives?
(BTW, pqee, I was looking over there to find the pet owner name function, and couldn't see one.)
HP and Power have wrapper functions for a couple reasons.
HP: The game returns 1 HP when you're dead. Most people find this annoying so the HP(unit) wrapper tests for this and shows 0 if the unit is dead. MaxHP(unit) exists for symmetry.
Power: If the unit is the player or the player's pet we need to flag the text for fast updates. This wrapper handles doing that for you. Again MaxPower(unit) exists for symmetry.
Both the Max functions aren't even actually separate functions they're just another name for UnitPowerMax and UnitHealthMax.
There's no function for finding the owner of a pet. You have to jump through some hoops to get that information.
Ok I am a beginner and I want to learn how to do this....my question is I enabled the LuaText module but where do I actually go to code, in the interface or in the LUA files outside the game?
Faction and PvP: A for alliance and H for horde, colored based on PvP flagg (about the same as the default names are colored). My faction green for pvp on, blue for pvp off. Opposite faction depends on my pvp state (yellow if im off and they are on, red if both are on and blue if both are off) Currently i only play alliance and tag might reflect that (i haven't made the tag myself so i don't really know)
I wrote up some code for your purpose. I don't know how well it works because I am at work and can't test it (don't tell my boss). Also, I added a tag for you being PvP flagged, but the unit not being flagged, I assumed Red. This could be made to automatically detect your faction, but that seems like a waste of resources, to adjust Alliance to Horde, just swap Alliance and Horde, and swap H and A
local fact = UnitFactionGroup(unit)
if fact=="Alliance" then
if UnitIsPVP("player") then
return "|cff00FF00A|r"
else
return "|cff0000FFA|r"
end
elseif fact=="Horde" then
if not UnitIsPVP("player") and UnitIsPVP(unit) then
return "|cffFFFF00H|r"
elseif UnitIsPVP("player") and UnitIsPVP(unit) then
return "|cffFF0000H|r"
elseif UnitIsPVP("player") and not UnitIsPVP(unit) then
return "|cffFF0000H|r"
elseif not UnitIsPVP("player") and not UnitIsPVP(unit) then
return "|cff0000FFH|r"
end
end
Ok I am a beginner and I want to learn how to do this....my question is I enabled the LuaText module but where do I actually go to code, in the interface or in the LUA files outside the game?
In the interface, the same place as for DogTagText
I wrote up some code for your purpose. I don't know how well it works because I am at work and can't test it (don't tell my boss). Also, I added a tag for you being PvP flagged, but the unit not being flagged, I assumed Red. This could be made to automatically detect your faction, but that seems like a waste of resources, to adjust Alliance to Horde, just swap Alliance and Horde, and swap H and A
local fact = UnitFactionGroup(unit)
if fact=="Alliance" then
if UnitIsPVP("player") then
return "|cff00FF00A|r"
else
return "|cff0000FFA|r"
end
elseif fact=="Horde"
if not UnitIsPVP("player") and UnitIsPVP(unit) then
return "|cffFFFF00H|r"
elseif UnitIsPVP("player") and UnitIsPVP(unit) then
return "|cffFF0000H|r"
elseif UnitIsPVP("player") and not UnitIsPVP(unit)
return "|cffFF0000H|r"
elseif not UnitIsPVP("player") and not UnitIsPVP(unit)
return "|cff0000FFH|r"
end
end
In the interface, the same place as for DogTagText
tested that but it pops an error:
[2009/06/19 22:50:07-3827-x1]: <string>:"PitBull4_LuaTexts:Target:Lua:PvP":9: 'then' expected near 'if'
PitBull4-r20090616012413\ModuleHandling\TextProviderModule.lua:116: in function `UpdateFrame'
PitBull4-r20090616012413\ModuleHandling\Module.lua:271: in function `Update'
PitBull4-r20090616012413\UnitFrame.lua:527: in function `Update'
PitBull4-r20090616012413\UnitFrame.lua:553: in function `UpdateGUID'
PitBull4-r20090616012413\Main.lua:1136: in function `CheckGUIDForUnitID'
PitBull4-r20090616012413\Main.lua:1141: in function `?'
CallbackHandler-1.0-3 (Ace3):146: in function <...Ons\Ace3\CallbackHandler-1.0\CallbackHandler-1.0.lua:146>
<string>:"safecall Dispatcher[1]":4: in function <[string "safecall Dispatcher[1]"]:4>
<in C code>: ?
<string>:"safecall Dispatcher[1]":13: in function `?'
CallbackHandler-1.0-3 (Ace3):91: in function `Fire'
AceEvent-3.0-3 (Ace3):119: in function <Interface\AddOns\Ace3\AceEvent-3.0\AceEvent-3.0.lua:118>
<in C code>: in function `TargetUnit'
Interface\FrameXML\SecureTemplates.lua:348: in function `handler':
Interface\FrameXML\SecureTemplates.lua:460: in function `SecureActionButton_OnClick':
Interface\FrameXML\SecureTemplates.lua:501: in function <Interface\FrameXML\SecureTemplates.lua:493>:
---
Yeah, it looks like Theondry caught my mistakes. Apparently I don't code as well at work, go figure.
Also, based on the line number in your error, it appears that you used a version of the code that I edited away. I got rid of the r,g,b assignments, combined with %20x$20x%20x, and just put the color assignment directly in. I am not sure if this helps performance an appreciable amount, I doubt it does, but it does make the code cleaner.
I'm having an issue with the one of the default Lua Text options - I assumed that Class:Short would give me Level & Class, but instead it is giving me Level & Race. Could someone please help me figure out how to make it display just Level & Class?
I feel like this is simple enough it should be glaringly obvious, but I'm a noob at this stuff.
Anybody could gimme a clue on how to make, via lua or dog tags, how to set the cast bar to show Name, Race and Level but hide them all while casting and show the spell name and cast time?
Thanks a lot :)
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
You don't want to call functions you have already defined. Here are minor changes to your code:
Regarding Guild info:
guildName, guildRankName, guildRankIndex = GetGuildInfo(unit)
Sweet, another minor lesson to add to it all (i dun know know anything about lua, just working with logic here)
Basically you need to check if the function returns nothing. You could do that with an if statement, or you can do what I did above. If guildName is assigned something (by a player in a guild) then that will be displayed. If nothing is assigned to guildName then instead of passing nil to the format function it will pass an empty string, which should stop the error.
That works, but i need to change the "|cffffffff<%s>|r" to hide the <> when there is no value displayed but im still to figure out the Angle stuff (still have no grasp of the formating)
Edit: If you don't need the other returns (rank and rank index), you don't need to include them on the first line.
will still give you the name and save less information in memory (small amount sure, but every little bit helps :))
And Satrina, no point in returning "" for nothing. Not returning anything handles that for you. It's not wrong or anything, just makes the code a bit longer for no real benefit.
Will give that a shot then (im still shotting blind here).
But i think i have gotten most of the texts working now (with some minor changes).
Pretty much only missing the Faction text now.
Given the context of much of Shefki's admonitions ("zomg! redundant calls!"), I'm clearly missing something.
What gives?
(BTW, pqee, I was looking over there to find the pet owner name function, and couldn't see one.)
Not using default one :p
Got it posted in the Elitist thread
This is what i used with dogtags
HP and Power have wrapper functions for a couple reasons.
HP: The game returns 1 HP when you're dead. Most people find this annoying so the HP(unit) wrapper tests for this and shows 0 if the unit is dead. MaxHP(unit) exists for symmetry.
Power: If the unit is the player or the player's pet we need to flag the text for fast updates. This wrapper handles doing that for you. Again MaxPower(unit) exists for symmetry.
Both the Max functions aren't even actually separate functions they're just another name for UnitPowerMax and UnitHealthMax.
There's no function for finding the owner of a pet. You have to jump through some hoops to get that information.
I wrote up some code for your purpose. I don't know how well it works because I am at work and can't test it (don't tell my boss). Also, I added a tag for you being PvP flagged, but the unit not being flagged, I assumed Red. This could be made to automatically detect your faction, but that seems like a waste of resources, to adjust Alliance to Horde, just swap Alliance and Horde, and swap H and A
In the interface, the same place as for DogTagText
tested that but it pops an error:
Tack "then" to the end of that line, and it should be okay.
Id est:
elseif fact=="Horde" then
Edit:
I looked more at that.
Make sure all the "elseif" lines end with "then".
Also, based on the line number in your error, it appears that you used a version of the code that I edited away. I got rid of the r,g,b assignments, combined with %20x$20x%20x, and just put the color assignment directly in. I am not sure if this helps performance an appreciable amount, I doubt it does, but it does make the code cleaner.
I feel like this is simple enough it should be glaringly obvious, but I'm a noob at this stuff.
Thanks, that fixed it.
How would i go about making
return Level(unit)
Not return ?? on bosses ?
Thanks a lot :)