Thread Tools Display Modes
08-04-09, 01:53 PM   #1
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Shorter way to do this?

I tried many different ways, that have all failed, so wondering if I'm just missing something to make this shorter:

Code:
CART_ActiveProfile[name] = {backdropColor = {r=1,g=1,b=1}}

f:SetBackdropColor(CART_ActiveProfile[name].backdropColor.r, CART_ActiveProfile[name].backdropColor.b, CART_ActiveProfile[name].backdropColor.g)
I've tried:
Code:
CART_ActiveProfile[name] = {backdropColor = {(1,1,1)}
f:SetBackdropColor(CART_ActiveProfile[name].backdropColor)
... but keeps coming back with errors. I've tried several different formats and only one I've been able to get to work correctly is the first example.

Last edited by Sythalin : 08-04-09 at 02:09 PM.
  Reply With Quote
08-04-09, 01:56 PM   #2
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Code:
local bcolour = CART_ActiveProfile[name].backdropColor
f:SetBackdropColor(bcolour.r, bcolour.g, bcolour.b)
or
Code:
local function getrgb(tbl) return tbl.r, tbl.g, tbl.b end
f:SetBackdropColor(getrgb(CART_ActiveProfile[name].backdropColor))

would also work.
  Reply With Quote
08-04-09, 02:12 PM   #3
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
Code:
CART_ActiveProfile[name] = {backdropColor = {1,1,1}}

f:SetBackdropColor(unpack(CART_ActiveProfile[name]))
  Reply With Quote
08-04-09, 02:14 PM   #4
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
Or unpacking the indexed array in your second example:
Code:
CART_ActiveProfile[name] = {backdropColor = {1,1,1}
f:SetBackdropColor(unpack(CART_ActiveProfile[name].backdropColor))
Note that I removed the () brackets in your first line, because I don't have any idea why they're there

EDIT: Waverian was faster :/
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
08-04-09, 02:20 PM   #5
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
Originally Posted by Cargor View Post
EDIT: Waverian was faster :/
Well, yours will actually work though. I guess we're even.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Shorter way to do this?


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