Jump to content
Sign in to follow this  
Senshi

get structuredtext from control

Recommended Posts

ctrlSetText and ctrlText work hand in hand on Text type controls.

For StructuredText type controls we do have ctrlSetStructuredText, but we do not have ctrlStructuredText to retrieve said text.

We can use ctrlText to get the text, but we lose all the "structured" elements, such as linebreaks.

Is there a way to retrieve the structuredtext of a control?

Example:

uiNamespace getVariable "HUD_MESSAGE" ctrlSetStructuredText(
composeText[
	composeText[ctrlText(uiNamespace getVariable "HUD_MESSAGE")],
	linebreak,
	format["%1", "Test"]
]
);

In theory, this snipped should produce a structuredtext looking like this if executed multiple times:

Test
Test
Test
Test

However, it actually results in:

TestTestTest
Test

This is because ctrlText does only return a "string" version of the actual structured text, omitting linebreaks. So, the inner composeText is useless. I also tried parseText and various other linebreak types ("</br>", "\n"), but couldn't find a working solution.

Do you have any suggestions?

Share this post


Link to post
Share on other sites

uiNamespace getVariable "HUD_MESSAGE" ctrlSetStructuredText (
composeText [
	parseText (ctrlText (uiNamespace getVariable "HUD_MESSAGE")),
	linebreak,
	format["%1", "Test"]
]
);

?

Share this post


Link to post
Share on other sites

I tried that already. Gives the same faulty result, because "ctrlText" does not return the linebreaks :( .

Share this post


Link to post
Share on other sites

Do you know where the control is in the config? You can get the raw string data (including strings used in the construction of structured text like "<br />") using getText. If your structured text was in your description.ext, for example, you could get its value using:

_rawStringValue = getText(missionConfigFile >> "myDialog" >> "myStructuredTextControl" >> "text");
_structuredValue = parseText(_rawStringValue);

Share this post


Link to post
Share on other sites

@ST_Dux: With this method, I can only retrieve the text value defined at initialization. This value is not updated to reflect the changes made dynamically during the mission. Thank you anyway, it's definitely a good workaround to get static data.

I guess I'll have to work around this missing command by storing the composed StructuredText in a dedicated variable. Feels wrong somehow...

Share this post


Link to post
Share on other sites
@ST_Dux: With this method, I can only retrieve the text value defined at initialization. This value is not updated to reflect the changes made dynamically during the mission. Thank you anyway, it's definitely a good workaround to get static data.

I guess I'll have to work around this missing command by storing the composed StructuredText in a dedicated variable. Feels wrong somehow...

Ah, that's a shame. I'm afraid that using an extra dedicated variable is really going to be your only option, then.

Share this post


Link to post
Share on other sites

Workaround isn't great, but it works good enough:

[color="#FF8040"][color="#000000"]_new[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
[color="#000000"]_target[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]

[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]![/b][/color][color="#191970"][b]isNil[/b][/color] [color="#7A7A7A"]"_target"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#000000"]playerSide[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#000000"]_target[/color][color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]else[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#000000"]true[/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]

[color="#1874CD"]_text_old[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]missionNamespace[/b][/color] [color="#191970"][b]getVariable[/b][/color] [color="#7A7A7A"]"ui_AAS_message_text"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]isNil[/b][/color] [color="#7A7A7A"]"_text_old"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
    [color="#191970"][b]missionNamespace[/b][/color] [color="#191970"][b]setVariable[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"ui_AAS_message_text"[/color][color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]""[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
	[color="#1874CD"]_text_old[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]missionNamespace[/b][/color] [color="#191970"][b]getVariable[/b][/color] [color="#7A7A7A"]"ui_AAS_message_text"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]count[/b][/color] [color="#1874CD"]_text_old[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#FF0000"]3[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
    [color="#1874CD"]_text_old[/color] [color="#191970"][b]resize[/b][/color] [color="#FF0000"]3[/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]


[color="#000000"]_new[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b][[/b][/color][color="#191970"][b]daytime[/b][/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]"HH:MM"[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_timeToString[color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]+[/b][/color] [color="#7A7A7A"]" "[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#000000"]_new[/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_text_old[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#1874CD"]_text_old[/color][color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#000000"]_new[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_arrayInsert[color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]missionNamespace[/b][/color] [color="#191970"][b]setVariable[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"ui_AAS_message_text"[/color][color="#8B3E2F"][b],[/b][/color] [color="#1874CD"]_text_old[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_structext[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]""[/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]{[/b][/color]
    [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_structext[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]""[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
        [color="#1874CD"]_structext[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]_x[/color][color="#8B3E2F"][b];[/b][/color]
    [color="#8B3E2F"][b]}[/b][/color][color="#191970"][b]else[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
    	[color="#1874CD"]_structext[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_structext[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#7A7A7A"]"<br/>"[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#000000"]_x[/color][color="#8B3E2F"][b];[/b][/color]
    [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]forEach[/b][/color] [color="#1874CD"]_text_old[/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_structext[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]parseText[/b][/color] [color="#1874CD"]_structext[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]uiNamespace[/b][/color] [color="#191970"][b]getVariable[/b][/color] [color="#7A7A7A"]"WGP_AAS_MESSAGE"[/color] [color="#191970"][b]ctrlSetStructuredText[/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_structext[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

Gives me a nice "newsticker" with the 4 most recent messages showing. With all the benefits of having StructuredText.

DTOGlth.jpg

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  

×