Define Text Colour

0 favourites
  • 4 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Problem Description

    OK... This might be a bug or it could be a feature request to alter apparently inconsistent editor behaviour, and an associated limitation this causes if you try and alter text object font colour by using variables.

    The problem here occurs if you try and use variables to define the colour of the text. This appears to be impossible and, if you try, the editor either rejects your attempts or accepts your input but then nothing changes when the layout is run.

    Attach a Capx

    capx

    Description of Capx

    One sprite with a string variable "rgb(255,255,0)", one global string of the same value, and one text object. On start of layout, the colour of the text font is altered by applying the value >rgb(255,255,0)<.

    Steps to Reproduce Bug

    • If you run the layout then the text object font colour is changed.
    • Place the global variable in the set font colour action. This is accepted by the editor, but when you run the layout the font colour is not changed.
    • Place the Sprite object variable in the set font colour action. This is rejected by the editor, even though it is a string (like the global variable).

    Observed Result

    As above.

    Expected Result

    I expected a text set colour action could be defined by the input of a string, allowing full control by variables.

    Affected Browsers

    • N/A

    Operating System and Service Pack

    W10 x64

    Construct 2 Version ID

    r241 64 bit

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It would be a nice feature if you could use a string to set the color instead of a number, since the rgb() expression just returns a number.

    I guess in the meantime you could make a function like this to convert a rgb string to a number.

    on function "rgbText"

    --- set return value to rgb(int(mid(tokenat(function.parameter(0), 0, ","), 4, 3)), int(tokenat(function.parameter(0), 1, ",")), int(tokenat(function.parameter(0), 2, ",")))

  • on function "rgbText"

    --- set return value to rgb(int(mid(tokenat(function.parameter(0), 0, ","), 4, 3)), int(tokenat(function.parameter(0), 1, ",")), int(tokenat(function.parameter(0), 2, ",")))

    Hi R0J0hound, - thanks - I see... I guess that's the way to go. No biggie in logic terms, but the editor still seems unhappy with some entry params. Perhaps this way of handling text colour is easy enough, so it might be worth an entry in the manual to save future frustrations.... Cheers.

  • Closing as not a bug: rgb() returns a number, not a string. So passing your string set in a global variable doesn't work for the same reason you can't set the text color to the string "foo" - it's not valid to pass a string there.

    Unfortunately you can't specify an expression as the initial value of a global variable, but you could just make it a number and set it to an rgb() expression on start of layout.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)