Jump to content
Benoit Katecpo

Can't parseText in for and forEach structure ?

Recommended Posts

Hello !

 

I've got a problem, I want to compose a text from and array with a for or foreach structure, BUT, I wan't to put some color in my strings, and as you'll see it didn't seems to work !

Why ?

I've tested 2 methods, one with the for structure, and the other one with a foreach structure, but in both cases, it didn't work ! No colors juste composed text :(

 

Here is the 1st method :

_txt = "";
for[{_i=0},{_i<(count arrayDump)},{_i=_i+1}] do
{
	_slct = (arrayDump select _i) select 1;
	_slct = parseText format["<t color='#FF0000'>%1</t>",_slct];
	_txt = format["%1 \n\n %2",_txt, _slct];
};
hint _txt;

2nd method :

_txt = "";  
{ 
_slct = nil;
_slct = (arrayDump select _foreachIndex) select 1;
_slct = parseText format["<t color='#FF0000'>%1</t>",_slct];
_txt = format["%1 \n\n %2",_txt,_slct];
} forEach arrayDump; 
hint _txt;

And arrayDump :

arrayDump = [[1,"A"],[2,"B"],[3,"C"],[4,"D"],[5,"E"]];

In all case I have :



A


B


C


D


E

But no color :( How can I put a color ?

 

Thanks in advance for your precious help !

 

 

Share this post


Link to post
Share on other sites

the only suggestion I have is to build the entire string unparsed and parse it at the end.

_txt = "";  
{ 
 _slct = (arrayDump select _foreachIndex) select 1;
 _txt = format["%1 \n\n <t color='#FF0000'>%2</t>",_txt,_slct];
} forEach arrayDump; 
hint parseText _txt;

but idk if that works.

Share this post


Link to post
Share on other sites

Took a couple of hours, but I got it:

arrayDump = [[1,"A"],[2,"B"],[3,"C"],[4,"D"],[5,"E"]];

_txt = "";

{
_slct = nil;
_slct = (arrayDump select _foreachIndex) select 1;
_slct = parseText format["<t color='#FF0000'>%1</t>",_slct];
_txt = format["%1 <br/><br/> %2",_txt,_slct];
} forEach arrayDump;

hint parseText format["<t color='#FF0000'>%1</t>",_txt];

Result:

YZ1UXch.jpg

Share this post


Link to post
Share on other sites

@sarogahtyp

I'll try ;)

 

@cx64

Thanks, but I've to color certain strings, sorry for inconvinience, I've not precise this, I'll try the first response and I'll tell you if it works ;)

 

@sarogahtyp

Thanks a lot !!! It works !

  • Like 1

Share this post


Link to post
Share on other sites

what do we learn from it?

u cant parse structured text again because it doesnt contain the xml tags and is converted to default text settings.

edit: thats nonsense ^^

edit2: i think the real reason is that u used format only without parseText as last operation on ur string before the hint.

format returns just a string and not structured text as needed...

instead of combineing format and parseText u can use formatText because its doing both in one.

https://community.bistudio.com/wiki/formatText

Share this post


Link to post
Share on other sites

@sarogahtyp

That's what I was thinking about ;)

 

And I've another question, is there any way to put a text background color ? With parseText (It's XML, background-color='#FFFFFF' doesn't work :()

 

Thanks in advance ;)

Share this post


Link to post
Share on other sites

@sarogahtyp

Yes I've searched here ^^ But I want to put multi background color in one string ^^ Not just one for all structured text ;)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×