Jump to content
Sign in to follow this  
terox

compose or parse text and a format ["%1",_mytext];

Recommended Posts

as a simple example, how would i implement a parsetext or composetext command to change the colour of the text of _message1

eg

_message1 = format ["%1" name player];

_message2 = format ["%1",typeof (vehicle player)];

(My_MessageRsc displayCtrl 903) ctrlSetText (format ["<< %1 >>     is in  %2 ", _message1, _message2]);

so that it outputs as

<span style='color:blue'><< Terox  >></span> is in a HMMWV

Share this post


Link to post
Share on other sites

very nice of you to link me to the wiki, however it's a solution i am looking for not a command reference link

and the control i am using is a structured text control

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

here's the actual code, which i didnt want to post because i didnt want to add to the complexity of the question

class ArchiveMessage_Txt : Message_Bkg

     {

        idc = 906;

type = CT_STRUCTURED_TEXT;

        lineSpacing = 1;

        colorText[] = {0,0,0,0.7};

        colorBackground[] = {0, 0, 0, 0};

        font = "TahomaB";

        sizeEx = 0.015;

        text = "No archived messages";

size = 0.016;

        y = 0.169;

        h = 0.3;

     };

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

private ["_temp","_tDelay","_count","_Id","_message1",_message2","_array","_t","_y"];

_tDelay = 0;

_array = [];

_temp = [];

_count = count Tx_Messages;

_Id = _count -1;

_label = "";

_t = "";

_display =  findDisplay 900;

_message1 = "";

_message2 = "";

{

_temp = _temp + [Tx_messages select _Id];

_Id = _Id -1;

}foreach Tx_Messages;

titleRsc["Tx_MessageRsc", "PLAIN"];

_Id = 0;

{

switch(_id ==0)do

{

case true:

{

_t = [Time-(_x select 1)]call Tx_fTimeToString;

{_message1 = _message1 + format ["   %1\n", _x]}foreach (_x select 2);

(Tx_MessageRsc displayCtrl 903) ctrlSetText (format ["<< %1 >>     received  %2   ago", _x select 0, _t]);

(Tx_MessageRsc displayCtrl 904) ctrlSetText _message1;

};

case false:

{

_t = [Time-(_x select 1)]call Tx_fTimeToString;

_message2 = _message2 + (format ["\n<< %1 >>     received  %2   ago\n", _x select 0,_t]);

_y = (_x select 2);

{_message2 = _message2 + format ["    %1",_x]}foreach _y;

_message2 = _message2 + format ["\n"];

(Tx_MessageRsc displayCtrl 906) ctrlSetText _message2;

};

};

_id = _id + 1;

}foreach _temp;

//

//_display = findDisplay 900;

//_display closeDisplay IDC_OK;

and here is what it ouputs

The control box used below the Last 2 messages title needs to have the

"<< Mission Status >> received x secs ago line written in blue

The code for this line is

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _message2 = _message2 + (format ["\n<< %1 >>     received  %2   ago\n", _x select 0,_t]);

messagesystem.jpg

Share this post


Link to post
Share on other sites

There's quite a few missions using it now, but I can't think of one right now. Check out the Dialog Framework as a guide. It's a little old now, but the parseText part won't have changed, plus includes a #include file you can use/modify for use inside scripts. It shows 3 examples of how to do the following:

Screenshot

th_HintStructuredText.jpg

Share this post


Link to post
Share on other sites
Quote[/b] ]very nice of you to link me to the wiki, however it's a solution i am looking for not a command reference link

Well the solution is on the links i posted..

if you took some time to actually read them you would find your solution.

example

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_strct = (findDisplay 510) displayCtrl 511;

_x = "<t color='#ffff00'>" + format["%1",name player]+"</t>";

_y = "<t color='#00ff00'>" + " is my name"+"</t>";

_z = _x + _y;

_strct ctrlSetStructuredText parseText _z;

Share this post


Link to post
Share on other sites

thanks for ther help... sorted.

For those of you having similar problems, a coupleof things i realised

format ["\n %1 mytext",name player];

when used within a parsetext environment will not create a new line, the "\n" is passed purely as a string

and if you were to enclose any formatted text within a <>, for example

_label = "Mission Status"

_message = format [" << %1 >>",_label;

then the %1 code wouldnt be displayed as the parsetext command is looking for a command function within those tags.

Here's the final code that i used

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _t = [Time-(_x select 1)]call Tx_fTimeToString;

_message2 = _message2 + "<t color='#0000ff'><br/>"+ (format ["** %1 ** received %2 ago", _x select 0,_t])+"<br/></t>";

_y = (_x select 2);

{_message2 = _message2 + format [" %1",_x]}foreach _y;

_message2 = _message2 + "<br/>";

(Tx_MessageRsc displayCtrl 906) ctrlSetStructuredText parseText _message2;

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
Sign in to follow this  

×