Thread Tools Display Modes
07-30-09, 06:57 AM   #1
Heimdall
A Murloc Raider
Join Date: Jul 2009
Posts: 9
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
  Reply With Quote
07-30-09, 07:04 AM   #2
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
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.
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
07-30-09, 07:13 AM   #3
Heimdall
A Murloc Raider
Join Date: Jul 2009
Posts: 9
Originally Posted by Cargor View Post
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
  Reply With Quote
07-30-09, 10:54 AM   #4
Heimdall
A Murloc Raider
Join Date: Jul 2009
Posts: 9
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
  Reply With Quote
07-30-09, 11:24 AM   #5
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
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
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
07-30-09, 12:07 PM   #6
Heimdall
A Murloc Raider
Join Date: Jul 2009
Posts: 9
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
  Reply With Quote
07-30-09, 12:13 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Is this something that you can't do with STUF's tag system?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-30-09, 12:33 PM   #8
Heimdall
A Murloc Raider
Join Date: Jul 2009
Posts: 9
Ok, for future reference i've done this ugly code here ():
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
  Reply With Quote
07-30-09, 12:41 PM   #9
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I'm still not sure why you didn't just use the regular (original) text patterns/tags to do this. 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.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-30-09, 01:26 PM   #10
jasje
A Chromatic Dragonspawn
 
jasje's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 150
Originally Posted by Seerah View Post
I'm still not sure why you didn't just use the regular (original) text patterns/tags to do this. 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
__________________

Tukui | Github
  Reply With Quote
07-30-09, 01:39 PM   #11
celebros
A Deviate Faerie Dragon
 
celebros's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 12
Originally Posted by Heimdall View Post
Ok, for future reference i've done this ugly code here ():
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
  Reply With Quote
07-31-09, 12:36 AM   #12
Heimdall
A Murloc Raider
Join Date: Jul 2009
Posts: 9
Originally Posted by Seerah View Post
I'm still not sure why you didn't just use the regular (original) text patterns/tags to do this. 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
  Reply With Quote
07-31-09, 12:42 AM   #13
Heimdall
A Murloc Raider
Join Date: Jul 2009
Posts: 9
Originally Posted by celebros View Post
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
  Reply With Quote
08-03-09, 01:31 PM   #14
Limb0
A Cobalt Mageweaver
 
Limb0's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2008
Posts: 220
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).
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » STUF Lua editor

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