set initial value to an rgb value

1 favourites
  • 6 posts
From the Asset Store
HSV RGB Color Picker and Converter for Construct 3
  • Is there any way to set initial values of variables to an rgb value?

    (string won't help, because when I try to use that to set a font color it says it doesn't accept a string)

  • Have you used one of the rgb expressions? These expressions are built so you can just plug in values representing the amount of red, green and blue to blend to get your desired color.

    rgba(r, g, b, a)

    rgba255(r, g, b, a)

    rgbEx(r, g, b)

    rgbEx255(r, g, b)

    For these expressions, r is for the red value, b is for the blue value and g is the green. In the 2 expressions not ending in 255, the value should be between 0 and 100. In the 2 expressions ending in 255 the value should be between 0 and 255.

    The a is for alpha and should be a number between 0 and 100 where 0 is completely transparent and 100 is completely opaque.

  • Thank you, InDWrekt! I appreciate the thorough answer.

    yes, that's what I'm using. But variables won't accept these expressions as initial values. (I actually found a 9 y old post, where Ashley confirmed it wasn't possible "yet", apparently nothing has changed there.)

    So it looks like I have to set up a global variable for every color and then on start of layout I need to set the value to rgb(r,g,b)

    Quite cumbersome. I wish I could just assign the expression to a text objects instance variables.

    For sprites I found a workaround: leaving dummy objects with the needed colors in the layout and at runtime putting their color values into global variables.

    This might not seem like a big difference, but it is, because colors need to be adjusted all the time while a project is in progress, so it's crucial to be able to change them in as little steps as possible.

    Unfortunately for text this workaround is not possible, because the color property of fonts seems to be "write only" for some reason. So I can't go like

    set ColorRight = ColorRightDummy.ColorValue


    Ok, you are trying to store the rgb expression itself in a variable. What you need to do is store the resultant value. Check out this example. It sets the value of an instance variable called Color on the text object using the rgbEx expression. It then uses that variable to set the font color. Remember, it is not the rgb expression that is important. It is the value that the expression returns. That value CAN be stored in a variable.

  • I also want to say, as with most questions, there are multiple ways to do what you are trying. For example, if you want more control over the color, use individual variables for each of the red, green and blue inputs. Then when you call the set font color, just plug these values into the inputs of the expression.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks! I'm not sure that example can help my case.

    I know I can set a variable to any rgb value by code. Dealing with r,g,b individually makes matters more complicated. I mean, I could create instance variables for all components, but that would also mean copy/pasting them individually every time I change them.

    The beauty of instance variables is that I can create different instances with individual properties by copy/pasting them in the editor, which is basically the only place where I can see my game elements and tweak them in context. For color that's more important than anything.

    So since I'll need to do that step anyways, (setting the font color to see how it looks on a particular instance), it would be great to be able to just copy it from the color slot to a variable slot of the already selected instance, instead of going to the event sheet, finding the variable there and pasting the value so the game can set the variable for me.

    If comparing font color by code would work, things would be even simpler. I could just have dedicated objects for my color presets, tweak the color of those and be done with it, because at runtime the game would just reference the template objects. That's what the whole idea of templates is all about, and it works great for sprites, but not for text.

    By the way I'm not trying to do rocket sience here. ;)

    I have one type of button with different colors based on context. Active, inactive, right answer, wrong answer. All I'm looking for is a convenient way to setup a template for each of those colors that I can edit intuitively.

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