XWidgetSoft Forum
https://xwidget.com/bbs/

Can I use a loop to change text colors?
https://xwidget.com/bbs/viewtopic.php?f=8&t=7065
Page 1 of 1

Author:  DanDaBear [ August 20th, 2019, 3:17 pm ]
Post subject:  Can I use a loop to change text colors?

Hi, As the subject says, I want to run a loop in the WidgetOnLoad function to change text colors, adding a numerical
variable to the text name. (IE: "text" + i + ".font.fill.color = TextColor1"), where 1 is added to i at the end of each loop.

I can do the code for the loop but when appending the variable it doesn't change the text colors. Is there a way to do this?
What command(s) do I need to make it work? Code I have tried is below.

The text components are named": text1, text2 etc. up to text15.
Code:
//   Color Variables
var TextColor1 = rgba(0,130,230,255);
var BorderColor = rgba(0,60,100,255);
var BackColor = rgba(0,0,0,127);
var LineColor = rgba(0,44,80,255);

function widgetOnLoad()
{
i=1
     while(i <=15)
     {
     "text" + i + ".font.fill.color = TextColor1";
     i++;
     }
}

I also tried:
Code:
eval("text" + i + ".font.fill.color = TextColor1");

and:
Code:
do{
"text" + i + ".font.fill.color = TextColor1";
}

I can see that I get the correct strings from the code loop but it doesn't change the text colors?

I have a text launcher with 75 different text components and I'd rather not have to add them all one by one if I don't have to.

If not, is there a way to have different widgets use the same variables?

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/