PDA

View Full Version : Setting a control's label programmatically



paulyhedral
March 13th, 2021, 21:38
I'm using a "string_labeled" control, and I want to update the label programmatically. It normally has a child tag, "labelres", that specifies the string resource to use for the label, but I can't figure out how to programmatically specify a string or another string resource.

Thanks in advance.

Trenloe
March 13th, 2021, 23:39
Refer to the Developer Guide -> Ruleset API Reference in the Wiki.

The stringcontrol guide is here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996645166/stringcontrol It inherits the "textbasecontrol" which has setValue - https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4096428/textbasecontrol#setValue

celestian
March 14th, 2021, 00:32
I'm using a "string_labeled" control, and I want to update the label programmatically. It normally has a child tag, "labelres", that specifies the string resource to use for the label, but I can't figure out how to programmatically specify a string or another string resource.

Thanks in advance.

Attach a script to the control or the windowclass depending on where you need to change it. Then reference the control by its name variable (name="THIS") and use THIS.setValue("Whatever this label should be.");

Also, read what Trenloe posted ;)

paulyhedral
March 14th, 2021, 06:48
I'm looking to set the label, not the value. The value appears above a horizontal line, and a label appears below it. Here's a snippet of the control:
<string_labeled name="guide_attr">
<anchored to="guide_skill" width="40" height="20">
<top />
<right anchor="left" offset="-5" />
</anchored>

<readonly /> <labelres>journey_party_roles_guide_attr_label</labelres>
<tooltip>journey_party_roles_guide_attr_tooltip</tooltip>
</string_labeled>


And what it looks like:
44832
It's the "labelres" ("NAME" in the attached image) value that I want to change.

damned
March 14th, 2021, 08:17
What is the use case?
In MoreCore I have a number of user-editable labels.

Trenloe
March 14th, 2021, 09:31
I'm looking to set the label, not the value.
A "string_labeled" control is a template based on the stringcontrol base control. To change the text in that control (the text of the label in this case) you need to change the value of the control with setValue

So what I and celestian mentioned above is accurate.

If you're running code within the window where the control is use guide_attr.setValue("my new text"); If you're running code within the label just use setValue("my new text") If you're running code somewhere else in the GUI you'll need to navigate the GUI hierarchy to reach the control.

paulyhedral
March 15th, 2021, 00:12
A "string_labeled" control is a template based on the stringcontrol base control. To change the text in that control (the text of the label in this case) you need to change the value of the control with setValue

Ah, I see. So it's just a matter of figuring out what the label sub-control is called, so I can call setValue on it? Awesome, thanks much!