Results 1 to 3 of 3

Thread: UI problem dynamically changing a default value

  1. #1

    UI problem dynamically changing a default value

    I was building an UI attached to an object. I wanted to be able to dynamically change the colour of multiple text elements at once without having to individually change the colour of each text element.
    To do this, I used the "Defaults" feature to define a colour for all of my text objects of class "colouredText" (#DA1917 = red).
    My UI contains two text elements with the class "colouredText" and a button that changes the color attribute of the default text element to a different colour (#1E87FF = blue).

    Both texts are red at the start, and I was expecting them to both get blue when clicking the button, but only the second text changed colour.

    Initial look:
    Look after clicking the button:

    Here is the code of my UI:
    <Panel position="0 0 -200" width="14.3%" height="8.7%">
        <Text id="defaultTextColour" class="colouredText" color="#DA1917" />
        <Text class="colouredText" fontSize="100">Text 1</Text>
        <Text class="colouredText" fontSize="100">Text 2</Text>
        <Button onClick="buttonOnClick" fontSize="100">Change text colour</Button>
    And here is the code of the object this UI is attached to:
    function buttonOnClick()
      self.UI.setAttribute("defaultTextColour", "color", "#1E87FF")

  2. #2
    After a bit more thinking about this, I think it may not be a bug.
    It may be that the "id="defaultTextColour"" of the default text element means that it tries to give that exact same id to every text element of class colouredText, which fails because you can't have multiple elements with the same id so only the last text element to be defined gets this id, and that's the one that gets its colour changed by the button click.

    If I'm correct, 1) sorry for reporting a bug that's not actually a bug and 2) I need to find another way to dynamically change the colour of multiple text elements at once without having to individually change the colour of each text element.

  3. #3
    I don't think it's the fault of having id in Defaults. IMO it's just assigning those Defaults when UI is created and changing them at runtime will never have any effect (unless you re-set the whole UI from scripting I guess). In your situation I'd just make a simple function that goes through every element and its children and updates the color property if you don't want to hardcode element IDs.

Similar Threads

  1. Replies: 3
    Last Post: 08-02-2018, 04:46 PM
  2. [SOLVED] Changing the camera FOV
    By Unreal_Ed in forum Suggestions
    Replies: 2
    Last Post: 12-14-2017, 06:25 PM
  3. Changing the card back?
    By MarcusRaven in forum Scripting
    Replies: 5
    Last Post: 07-14-2017, 12:41 PM
  4. Changing the Background using Scripting
    By Mark in forum Scripting
    Replies: 0
    Last Post: 10-16-2016, 04:09 PM
  5. Dynamically set the board image
    By ootm in forum Scripting
    Replies: 1
    Last Post: 07-09-2016, 11:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts