Shorter Code

Is there a shorter version of this code?\r\rfunction change (colorNumber, colour) {\r&nbsp &nbsp &nbsp &nbsp if (colorNumber == 0) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp color0.setRGB(colour);\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp if (colorNumber == 1) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp color1.setRGB(colour);\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp if (colorNumber == 2) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp color2.setRGB(colour);\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp if (colorNumber == 3) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp color3.setRGB(colour);\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp if (colorNumber == 4) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp color4.setRGB(colour);\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp if (colorNumber == 5) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp color5.setRGB(colour);\r&nbsp &nbsp &nbsp &nbsp }\r}\r\r\rI tried this:\r\rfunction change(name, colour) {\r name.setRGB(colour);\r}\r\rIf I call this function from some other code, syntax is this\r\rchange(“color” add colorNumber, 0x999999);\r\r…but it didn’t work.\r\rCould somebody please help me?

The function was almost perfect. In a dot syntax call, you can’t use a variable in the string of objects, without having a distinguishing marker. The A/S engineers picked [ ].\r\rso\r\rfunction change(name, colour) {\r[name].setRGB(colour);\r}\r\rshould work… if I’m reading this correctly.

Why not something like

 for (i=0;i<=5;i++) {\r\rthis["color"+i].setRGB(colour);\r\r}

It might work.\rpom 0]

I solved it.\r\rI did this instead.\r\rfunction changeColor (colorNumber, colour) {\r (eval(“color” add colorNumber)).setRGB(colour);\r}\r\rI tried your suggestions. It still didn’t work.\r\rThanks for helping.