WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   STUF Lua editor (https://www.wowinterface.com/forums/showthread.php?t=25847)

Heimdall 07-30-09 06:57 AM

STUF Lua editor
 
Hi all,
i'm trying to color a string using the class color in STUF, the problem is that i don't know how to do that...
I tryied usin the table RAID_CLASS_COLORS but i must be missing something:

local DB = {}
for class, color in pairs(RAID_CLASS_COLORS) do
DB.[class] = { color.r, color.g, color.b }
end

This code seems to be wrong or i can't access the table RAID_CLASS_COLORS but i don't get any error in that way however it seems that the structure DB in empty....
There another way to do that? Maybe using the 'cache' parameter? But using cache i only know how to get info like name, level ecc (info that anyway i can get using standard API), any thoughts?

Thank you

xConStruct 07-30-09 07:04 AM

Code:

DB.[class] = { color.r, color.g, color.b }
The dot doesn't belong here and likely causes errors :)
Otherwise I don't have any idea of STUF.

Heimdall 07-30-09 07:13 AM

Quote:

Originally Posted by Cargor (Post 149972)
Code:

DB.[class] = { color.r, color.g, color.b }
The dot doesn't belong here and likely causes errors :)
Otherwise I don't have any idea of STUF.

You are right about the dot, let's hope is the reason of my problem ;)
as soon as i get home i'll check in game what happens.

thanks for the help

Heimdall 07-30-09 10:54 AM

I don't know,
for example this simple code here:

Code:

function(unit, cache)
local DB = {}
for class, color in pairs(RAID_CLASS_COLORS) do
DB[class] = { class }
end
return DB["ROGUE"]
end

i take an error (string expected, got table). i need some time to figure out how the tables work because i was expecting to get the string "ROGUE" as a result...

Regards

xConStruct 07-30-09 11:24 AM

Because you put the class in { } brackets, there's a sub-table created for the class-string.

So, just write DB[class] = class to correct it.

But I'm wondering what you're trying to achieve, because you basically get "ROGUE" back, if you're accessing the table with "ROGUE"?

Normally class colors are stored in RAID_CLASS_COLORS and you just can access them via RAID_CLASS_COLORS["ROGUE"]. It returns a table holding the r,g,b, a-values for the color.
And then you'd have to return it in the correct format (and there's the problem that I don't know, how STUF wants the data back).

So basically, what string should the function return? Just the name, a classcolored name or just the class-color-values? That's not really clear for me ;)

Heimdall 07-30-09 12:07 PM

Actually i want a class-colored text and i need the rgb code for that but i can't get it and unpack in three local variables, i'll give it a try after dinner ;)

Seerah 07-30-09 12:13 PM

Is this something that you can't do with STUF's tag system?

Heimdall 07-30-09 12:33 PM

Ok, for future reference i've done this ugly code here (:D):
Code:

function(unit, cache)
DB = {}
for class, color in pairs(RAID_CLASS_COLORS) do
DB[class] = { r=color.r, g=color.g, b=color.b}
end
r = DB["PALADIN"].r
g = DB["PALADIN"].g
b = DB["PALADIN"].b
return "|cff%02x%02x%02x%s",r*255,g*255,b*255,cache.level
end

it color the level with the class color (it's not what i needed in the beginning but at least i colored something :P)

Regards

Seerah 07-30-09 12:41 PM

I'm still not sure why you didn't just use the regular (original) text patterns/tags to do this. :p I haven't been playing wow, so I don't recall exactly (there's a help window in-game), but it would just be level:class or somesuch.

jasje 07-30-09 01:26 PM

Quote:

Originally Posted by Seerah (Post 150011)
I'm still not sure why you didn't just use the regular (original) text patterns/tags to do this. :p I haven't been playing wow, so I don't recall exactly (there's a help window in-game), but it would just be level:class or somesuch.


[classcolor=level] ? or is that dogtags

celebros 07-30-09 01:39 PM

Quote:

Originally Posted by Heimdall (Post 150010)
Ok, for future reference i've done this ugly code here (:D):
Code:

function(unit, cache)
DB = {}
...
DB[class] = { r=color.r, g=color.g, b=color.b}
...


I'm not sure why you're wasting tables here though.
You're creating a DB table, and then one extra table for every class, every time this function is called (yes they will be collected but why waste the cycles in the first place?

Why can't you do:

Code:

for class, color in pairs(RAID_CLASS_COLORS) do
    if CLASS == "PALADIN" then
        return string.format("cff%02x%02x%02x%s",color.r*255,color.g*255,color.b*255,cache.level)
    end
end

Or better yet:

Code:

function (unit, cache)
    local _,class = UnitClass(unit)
    local color = RAID_CLASS_COLORS[class]
    if color then
        return string.format("cff%02x%02x%02x%s",color.r*255, color.g*255,color.b*255, cache.level)
    else
        return cache.level
    end
end


Heimdall 07-31-09 12:36 AM

Quote:

Originally Posted by Seerah (Post 150011)
I'm still not sure why you didn't just use the regular (original) text patterns/tags to do this. :p I haven't been playing wow, so I don't recall exactly (there's a help window in-game), but it would just be level:class or somesuch.

Because i had to truncate a string and to do a check on the power value, and also i want to experiment with lua :P

Heimdall 07-31-09 12:42 AM

Quote:

Originally Posted by celebros (Post 150022)
I'm not sure why you're wasting tables here though.
You're creating a DB table, and then one extra table for every class, every time this function is called (yes they will be collected but why waste the cycles in the first place?

Why can't you do:

Code:

for class, color in pairs(RAID_CLASS_COLORS) do
    if CLASS == "PALADIN" then
        return string.format("cff%02x%02x%02x%s",color.r*255,color.g*255,color.b*255,cache.level)
    end
end

Or better yet:

Code:

function (unit, cache)
    local _,class = UnitClass(unit)
    local color = RAID_CLASS_COLORS[class]
    if color then
        return string.format("cff%02x%02x%02x%s",color.r*255, color.g*255,color.b*255, cache.level)
    else
        return cache.level
    end
end


Thanks for the tip, i will test this when at home today, i'm new to Lua and i still don't know enough, also i didn't know that UnitClass return two strings (the second one that i need is capitalized), in my code i used the function string.upper(value) to do that.

Regards

Limb0 08-03-09 01:31 PM

Stuf has tons of options and is extremely configurable and easy to get lost in... from what I've read here, everything you want to do can be done with Stuf's "dogtags."

Sample text coding for hp
[difficulty:curhp] [hpthreshold:(][hpthreshold:perchp][hpthreshold:%][hpthreshold:)]

If you guys are exploring LUA, then definitely cool discussion, but if you simply want to make Stuf look nice, use the in game editor, or just pull my Stuf and StufRaid layouts from my UI.. (completely color coded, with a cowtip feel regarding info).


All times are GMT -6. The time now is 04:38 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI