Quantcast
Need help with Stuf Unit Frames custom LUA - WoWInterface
Thread Tools Display Modes
11-18-15, 06:47 AM   #1
Darsyek
A Murloc Raider
Join Date: Nov 2015
Posts: 5
Need help with Stuf Unit Frames custom LUA

Hey there,

As the title suggests, I'm looking for some help with some custom LUA coding for Stuf Unit Frames. I'll try to be as specific as I can be while trying this at 5:45am.

What I'm trying to do is have my power bar display a percentage for any class that uses mana and a flat number for everything else (ie. energy, rage, runic power, focus, etc.)

I've spent a couple hours researching the UnitPower LUA stuff, but I just couldn't get it to work. Here's the code I have so far:

Code:
function(unit, cache, textframe)
if UnitPowerType("player") == 0 then
    local z = math.max(0, UnitPower("player")) / math.max(1, UnitPowerMax("player")) * 100;
    return string.format("%.f", z) .. "%%";
else return UnitPower("player") end
Any help would be greatly appreciated.
  Reply With Quote
11-18-15, 12:40 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,231
Code:
if UnitPowerType("player") == 0 then
    return math.ceil(UnitPower("player") / UnitPowerMax("player") * 100) .."%"
else 
    return UnitPower("player") 
end
Your function didn't have an end statement but I'm asuming was just missed in the copy.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 11-18-15 at 03:17 PM.
  Reply With Quote
11-18-15, 04:46 PM   #3
Darsyek
A Murloc Raider
Join Date: Nov 2015
Posts: 5
Thank you for your reply. My previous code did actually have an end statement. It was tucked away at the end of the else statement. Unfortunately, your code doesn't seem to work for me either. The power bar is just blank, which I really don't understand. It's like the code isn't even getting past the if statement.

I did a little bit of testing with the code, and I can get it to display UnitPowerType as text or UnitPower as a flat unit, so I know it can handle those arguments, but for whatever reason it seems to stall on the if statements. I even tried to set up a local variable and use that in the if statement to display just plain text and it didn't work. I'm beginning to wonder if Stuf Unit Frames even allows if statements at all. D:

Last edited by Darsyek : 11-18-15 at 04:51 PM.
  Reply With Quote
11-18-15, 05:10 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,059
Originally Posted by Darsyek View Post
Thank you for your reply. My previous code did actually have an end statement. It was tucked away at the end of the else statement.
Your posted code does not have an "end" for the function, only the "if" statement.

If that is your actual code then it would be throwing a lua error.
  Reply With Quote
11-18-15, 06:21 PM   #5
Darsyek
A Murloc Raider
Join Date: Nov 2015
Posts: 5
Code:
function(unit, cache, textframe)
if UnitPowerType("player") == 0 then
    local z = math.max(0, UnitPower("player")) / math.max(1, UnitPowerMax("player")) * 100;
    return string.format("%.f", z) .. "%%";
else return UnitPower("player") end
That is the exact code from my original post. You can even go read the code from the original post. I haven't even edited it, it's exactly as it was when I posted it in the first place. Note the last line again: else return UnitPower("player") end. Like I said, my original code does have an end statement - at the end of the else statement. Changing what line the end statement is on makes no impact on its function (or lack thereof). Stuf Unit Frames also doesn't display any LUA errors when you're using custom code. It seems to suppress it, otherwise I'd be looking through the error logs myself.

Last edited by Darsyek : 11-18-15 at 06:25 PM.
  Reply With Quote
11-18-15, 06:23 PM   #6
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,059
You need another end at the end of that to close the function.

You are only closing the "if" statement. You aren't closing the function.

Lua errors need to be enabled through the "help" section of the in-game escape menu if they aren't enabled.
  Reply With Quote
11-18-15, 06:35 PM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,231
Your code:
Code:
function(unit, cache, textframe)
    if UnitPowerType("player") == 0 then
        local z = math.max(0, UnitPower("player")) / math.max(1, UnitPowerMax("player")) * 100;
        return string.format("%.f", z) .. "%%";
    else 
        return UnitPower("player") 
    end
Proper code:
Code:
function(unit, cache, textframe)
    if UnitPowerType("player") == 0 then
        local z = math.max(0, UnitPower("player")) / math.max(1, UnitPowerMax("player")) * 100;
        return string.format("%.f", z) .. "%%";
    else 
        return UnitPower("player") 
    end
end
Proper indentation helps.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
11-18-15, 07:10 PM   #8
Darsyek
A Murloc Raider
Join Date: Nov 2015
Posts: 5
Well. I feel like an idiot now. I had been assuming that the end statement was for the function as a whole. I suppose I should have realized that, considering my programming background is with C and C++. I suppose I should have assumed that the end statement worked like } does in those languages or that you couldn't write an if else statement without closing the else like C++. I have a lot to learn about LUA still it seems. I really appreciate your help, both of you. :P Sorry if I seemed like an ass.

In any case, it seems that it works now. Even with my original code. I just needed that extra end. Damn curly brackets were always the bane of my existence with C++ too. >_>
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Need help with Stuf Unit Frames custom LUA

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