Set text color by variable?

1 favourites
  • 9 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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 doesn�t work. I guess it�s because of the "Type: Text". So perhaps it can be done by two variables? I have tried but you can�t split the nummers by ",".

    Any ideas?

  • 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 helps

  • 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 (:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Great. Fast and helpful! Thank you guys!

  • Yeah. I was going over the "unanswered topics" and didnt check if it was C2 ;)

  • 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)+")

  • 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).

  • Thank you Ashley!

    edit: It works!

  • 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

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