Thread Tools Display Modes
04/01/14, 03:32 AM   #1
Tingle0x539
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 25
Returning multiple values, what?

GetColorAsRGB()

Returns: number red, number green, number blue

Can someone explain how to read this, I have never encountered a function that returns 3 separate values. Printing out what it returns gives me 1 all the time, how do I read the individual ones?

Edit, think I figured it out: local r, g, b = GetColorAsRGB();
But r g and b are all returning 1, so not sure if I did this correctly.

Last edited by Tingle0x539 : 04/01/14 at 03:43 AM.
  Reply With Quote
04/01/14, 05:53 AM   #2
Tajin
 
Tajin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 29
I assume that this function requires some arguments to work, surely it can not pull the RGBcode out of thin air?
  Reply With Quote
04/01/14, 05:57 AM   #3
Sideshow
 
Sideshow's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 36
Originally Posted by Tingle0x539 View Post
GetColorAsRGB()

Returns: number red, number green, number blue

Can someone explain how to read this, I have never encountered a function that returns 3 separate values. Printing out what it returns gives me 1 all the time, how do I read the individual ones?

Edit, think I figured it out: local r, g, b = GetColorAsRGB();
But r g and b are all returning 1, so not sure if I did this correctly.
I suspect a color is needed as argument.
local r, g, b = GetColorAsRGB(myColorVariable);
  Reply With Quote
04/01/14, 06:07 AM   #4
skyraker
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 154
Originally Posted by Tingle0x539 View Post
GetColorAsRGB()

Returns: number red, number green, number blue

Can someone explain how to read this, I have never encountered a function that returns 3 separate values. Printing out what it returns gives me 1 all the time, how do I read the individual ones?

Edit, think I figured it out: local r, g, b = GetColorAsRGB();
But r g and b are all returning 1, so not sure if I did this correctly.
The color code in game is given as an RGB value from 0 to 1, and correlates to a percentage-type of value for each color.

Are you certain that it doesn't return 4 values? When we set colors in controls (ie a label control), we send SetColor(number r, number g, number b, number a), with the first three as discussed and a is the alpha-value.

EDIT: I see which function you are using, and there are only three parameters. But what I said about values is correct.
  Reply With Quote
04/01/14, 08:16 AM   #5
Pawkette
 
Pawkette's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 20
Lua Code:
  1. ZO_ColorDef = ZO_Object:Subclass()
  2.  
  3. function ZO_ColorDef:New(r, g, b, a)
  4.     local c = ZO_Object.New(self)
  5.    
  6.     if(type(r) == "string") then            
  7.         c.a, c.r, c.g, c.b = ConvertHTMLColorToFloatValues(r)
  8.     elseif(type(r) == "table") then
  9.         local otherColorDef = r
  10.         c.r = otherColorDef.r or 1
  11.         c.g = otherColorDef.g or 1
  12.         c.b = otherColorDef.b or 1
  13.         c.a = otherColorDef.a or 1
  14.     else
  15.         c.r = r or 1
  16.         c.g = g or 1
  17.         c.b = b or 1
  18.         c.a = a or 1
  19.     end
  20.  
  21.     return c
  22. end
  23.  
  24. function ZO_ColorDef:FromInterfaceColor(colorType, fieldValue)
  25.     return ZO_ColorDef:New(GetInterfaceColor(colorType, fieldValue))
  26. end
  27.  
  28. function ZO_ColorDef:UnpackRGB()
  29.     return self.r, self.g, self.b
  30. end
  31.  
  32. function ZO_ColorDef:UnpackRGBA()
  33.     return self.r, self.g, self.b, self.a
  34. end
  35.  
  36. function ZO_ColorDef:SetRGB(r, g, b)
  37.     self.r = r
  38.     self.g = g
  39.     self.b = b
  40. end
  41.  
  42. function ZO_ColorDef:SetRGBA(r, g, b, a)
  43.     self.r = r
  44.     self.g = g
  45.     self.b = b
  46.     self.a = a
  47. end
  48.  
  49. function ZO_ColorDef:SetAlpha(a)
  50.     self.a = a
  51. end
  52.  
  53. function ZO_ColorDef:Clone()
  54.     return ZO_ColorDef:New(self:UnpackRGBA())
  55. end
  56.  
  57. function ZO_ColorDef:ToHex()
  58.     return string.format("%.2x%.2x%.2x", zo_floor(self.r * 255), zo_floor(self.g * 255), zo_floor(self.b * 255))
  59. end
  60.  
  61. function ZO_ColorDef:Colorize(text)
  62.     local combineTable = { "|c", self:ToHex(), tostring(text), "|r" }
  63.     return table.concat(combineTable)
  64. end
  65.  
  66. function ZO_ColorDef:Lerp(colorToLerpTorwards, amount)
  67.     return ZO_ColorDef:New(
  68.         zo_lerp(self.r, colorToLerpTorwards.r, amount),
  69.         zo_lerp(self.g, colorToLerpTorwards.g, amount),
  70.         zo_lerp(self.b, colorToLerpTorwards.b, amount),
  71.         zo_lerp(self.a, colorToLerpTorwards.a, amount)
  72.     )
  73. end
  Reply With Quote
04/01/14, 08:42 AM   #6
Tingle0x539
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 25
Sorry I didn't reply, this is the proper usage:
Lua Code:
  1. colorWheel = WINDOW_MANAGER:CreateControl("MyColorWheel", parent, CT_COLORSELECT)
  2. colorWheel:SetAnchor(BOTTOMLEFT, parent, BOTTOMLEFT, -64, 64)
  3. colorWheel:SetDrawLayer(0)
  4. colorWheel:SetDimensions(64, 64)
  5. colorWheel:SetMouseEnabled(true) // This is what was missing, enabling this allows the color selection wheel to accept mouse input for its needed internal functions
  6. colorWheel:SetHidden(false)

Now after clicking, one can retrieve the color with
Lua Code:
  1. local red, green, blue = colorWheel:GetColorAsRGB();

Which are floats ranging from 0.0 also to 1.0 (0-255/0x00-0xFF)

I have not yet gotten the WheelThumb to work, but it is not needed. Clicking plainly on the wheel sets internal variables to the corresponding color one has clicked on.

Last edited by Tingle0x539 : 04/01/14 at 09:42 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Returning multiple values, what?

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