Define Text Colour

Bugs will be moved here once resolved.

Post » Mon Dec 26, 2016 10:38 pm

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
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,193

Post » Mon Dec 26, 2016 11:13 pm

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, ",")))
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Mon Dec 26, 2016 11:20 pm

R0J0hound wrote: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.
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,193

Post » Thu Jan 19, 2017 4:40 pm

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.
Scirra Founder
B
387
S
230
G
88
Posts: 24,249
Reputation: 192,450


Return to Closed bugs

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests