Set text color by variable?

Get help using Construct 2

Post » Fri Jan 06, 2012 3:40 pm

Hey everybody. I like the use of global variables. But how can I make a global variable for the text color?

Here is what I did:

Name: textColor
Type: Text

Initial value: rgb(102, 153, 255)

It doesnt work. I guess its because of the "Type: Text". So perhaps it can be done by two variables? I have tried but you cant split the nummers by ",".

Any ideas?
B
14
S
2
G
6
Posts: 110
Reputation: 3,849

Post » Fri Jan 06, 2012 4:33 pm

You could make the code like:
set variable:
"rgb("+str(102)+","+str(153)+","+str(255)+")"

OR
set variable:
"rgb("+str(global('Variable1'))+","+str(global('Variable2'))+","+str(global('Variable3'))+")"

FYI: The "str(Value)" means that the number is converted into a string.

Hope this helpssiron2012-01-06 16:37:22
B
14
S
2
G
1
Posts: 28
Reputation: 1,152

Post » Fri Jan 06, 2012 4:41 pm

@siron
Oh a lost Construct Classic user :D welcome \o

Yeah colors are vector type variables (which means they have components)
Its a bit like position, if you want to store a position you need two variables (X and Y components)
So if you want to store a color you need 3 (Red,Green and Blue or Hue,Saturation,Brightness) maybe 4 if you add Alpha (:Yann2012-01-06 16:42:21
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Jan 06, 2012 4:50 pm

Great. Fast and helpful! Thank you guys!
B
14
S
2
G
6
Posts: 110
Reputation: 3,849

Post » Fri Jan 06, 2012 10:02 pm

Yeah. I was going over the "unanswered topics" and didnt check if it was C2 ;)
B
14
S
2
G
1
Posts: 28
Reputation: 1,152

Post » Mon Jan 09, 2012 2:57 pm

I have tested it. But it doesnt work.
Here is what Ive done:

Name: textcolor
Type: Text
Initial value: rgb("+str(102)+","+str(153)+","+str(255)+")

And I said (for testing) Set text to: textcolor

Text displays: rgb("+str(102)+","+str(153)+","+str(255)+")
B
14
S
2
G
6
Posts: 110
Reputation: 3,849

Post » Mon Jan 09, 2012 3:06 pm

Colors are numbers. rgb(r, g, b) is a system expression returning a number with all three color values stored in it. Text variables won't work!

Also, you can't use an expression for the initial value of an event variable yet, right now it has to be either a single number or text. So just do: start of layout - set text color to rgb(red_value, green_value, blue_value).
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Jan 09, 2012 3:13 pm

Thank you Ashley!

edit: It works!TastyBytes2012-01-09 15:29:41
B
14
S
2
G
6
Posts: 110
Reputation: 3,849

Post » Mon Jan 09, 2012 3:36 pm

I didn't knew about the rgb(r,g,b) function, so I did a calculation for setting color: r + g*255 + b*65025
Just throwing this in as extra info
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134


Return to How do I....?

Who is online

Users browsing this forum: Ethan, makkancs, Yahoo [Bot] and 29 guests