How do I compare text color?

0 favourites
  • 9 posts
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • I'm confused. I'm trying to read the color from a text object. But apparently there is only the Set font color action, but no way to read the color and store it in a variable?

    How would I set a new text objects font color to match another already existing text object's color at runtime?

  • When you set the color of the text, you can also save what it was set to in an instance variable for future reference.

  • I know, it's just such a simple thing that it seems odd it's not possible. I mean font color IS obviously a property, so why not make it accessible?

    I have a bunch templates for buttons with text. On start of layout I read the colors from those and save them to variables.

    This way I can make my tweaks WYSIWYG directly in the layout without manually having to copy/paste rgb values every time I decide to adjust a color.

    Make font slightly darker, deselect object to see the actual color without the blue selection tint, reselect font scroll back to color swatch, open and copy rgb to clipboard, open event sheet, find the corresponding variable, double click, select value, paste and close... you get the idea.

  • I do not konow if it is a proper way, but i did it like that yadi.sk/i/GHMCD6dmVp_G9w

  • Sorry, mistake, like this yadi.sk/i/rbBsBU_Huxk3Zw

  • Thanks, mtzvd! Could you explain what JSON.Get() part is doing and where it is getting the colors from in your example?

    I've never used it before and have no idea what it does.. ;)

  • Well, what I do is I use .asJSON to save properties from Text object. And I get something like this

    {"c3":true,"w":{"x":93,"y":64,"w":200,"h":30,"l":919232524966002,"zi":0,"oX":0,"oY":0},"data":{"t":"Text","c":[0.39215686274509803,0,0,0],"fn":"Arial","ps":12,"bbc":true}}
    

    So I see that inside this JSON text object "data" contains property "c" which is array of 4 of numbers from 0 to 1. Which is r g b and alfa - font color of Text object. Then I parse text to JSON to get actual values inside JSON object. And I need to get following path to get array elements: data.c.0 data.c.1 data.c.2 . I use JSON.GET(%path%) for each of those paths and set color of newText object accordingly.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • And .get(%path%) expression of JSON object just gets the value at given path of JSON https://www.construct.net/en/make-games/manuals/construct-3/plugin-reference/json

  • Cool, thank you! Now I understand how to use it. That's a cool trick to know as a workaround!

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