SetFillColor

Hi

why does this not work? I want to pass a variable from the table to set the fill colour but it does not work. the variable is been passed ok. 

Thank you

local MyColors = {}

  

MyColors[1] = “0,0,255” --blue

MyColors[2] = “255,0,0” --red

MyColors[3] = “255,255,0” --Yellow

MyColors[4] = “0,128,0” --green

MyColors[5] = “128,0,128” --purple

MyColors[6] = “255,255,0” --Yellow

MyColors[7] = “128.0,128” --purple

MyColors[8] = “0,128,0” --green

MyColors[9] = “0,0,255” --blue

MyColors[10] = “0,0,255” --blue

print(“color is”, MyColors[1])  --Prints 0,0,255

local col1 = display.newRect( display.contentWidth*0.25, display.contentHeight - 140, 70, 70 )

col1.strokeWidth = 1

col1:setFillColor(MyColors[1])

col1:setStrokeColor( 1, 0, 0 )

Incorrect format.

You can do something like this:

MyColors[1] = { 0.5, 0, 1 }

Then:

object:SetFillColor( unpack( MyColors[1] )

For instance

define the table as the previous poster noted, but also, the colors need to be in 0-1 not 0 to 255 (float not integer)

MyColors[1] = {0,0,1} --blue

MyColors[2] = {1,0,0} --red

MyColors[3] = {1,1,0} --Yellow

MyColors[4] = {0,0.5,0} --green

You are correct, the colors do need to be in that range, which goes against the grain for me, so i keep forgetting.

I will modify my post to prevent confusion.

works great thank you. I had the values as  string 

MyColors[1] = “0,0,1”  

and as replied should have been  MyColors[1] = {0,0,1} --blue

Incorrect format.

You can do something like this:

MyColors[1] = { 0.5, 0, 1 }

Then:

object:SetFillColor( unpack( MyColors[1] )

For instance

define the table as the previous poster noted, but also, the colors need to be in 0-1 not 0 to 255 (float not integer)

MyColors[1] = {0,0,1} --blue

MyColors[2] = {1,0,0} --red

MyColors[3] = {1,1,0} --Yellow

MyColors[4] = {0,0.5,0} --green

You are correct, the colors do need to be in that range, which goes against the grain for me, so i keep forgetting.

I will modify my post to prevent confusion.

works great thank you. I had the values as  string 

MyColors[1] = “0,0,1”  

and as replied should have been  MyColors[1] = {0,0,1} --blue