How do I Set Color (EFFECT) random ?

0 favourites
  • 12 posts
From the Asset Store
Color all tiles with the same color in 22 moves or less!
  • Hi All,

    How do I set a random color for each objects?

    All objects are in one family: "Created_Objects"

    I want to code for the family so it will work for any other object and it's instances.

    I started with this, but of course it keep setting it forever (trigger once didn't do the job and also for each loop failed) so I need to make it work once, ONLY every time I select an instance:

    My unfinished try:

  • You can apply right at the time you toggle the Boolean

  • Also make sure for your random formula to be: "int(random(256))"

    This will return a random integer from 0 to 255, and no floating number which possibly isn't a valid color.

  • Thanks Maverick1912 and Kyatric I tried to follow your instructions, but I get 99% of the selected objects the default color (which is Red for now).

    How can I make it more Random to select different colors and not mostly Red?

    BTW - I'm trying to make this work for mouse since I'm not using the touch object.

    My current test:

  • Consider using rgbEX instead of rgba.

    Nevertheless, normally this should work though.

    Consider posting your project for actual investigation, perhaps the issue is coming from some other interaction not displayed on this screenshot.

  • Note rgba takes values in the range 0-100, not 0-255. It's also fine to pass floats to these expressions - any rounding or clamping is done internally in the expression.

  • Thanks for the detailed reply, I appreciate it!

    So I created a clean example project so I can share here since my project is getting very complicated (especially for me as a noob), I do many mistakes and still can't solve many simple problems.

    the reason I prefer to use the SetColor is because I have extra control with the Alpha for opacity, but if it's not possible to use it I'll be happy to use the other option.

    As you can see I didn't solve the color selection in that project maybe you can help me out here.

    Also, I made a OFF-TOPIC point to show that what Ashley said:

    Note rgba takes values in the range 0-100, not 0-255. It's also fine to pass floats to these expressions - any rounding or clamping is done internally in the expression.

    Is not accurate at least on the current version and I wondered why it is not fixed on the expression tip that suggest 0-100 for every color while it is obviously 0-255 for RGB and 0-100 only for Alpha, this is how I'm used to it on animation software so it's great!

    File Example, as you can see I can SetColor from 0-255 for the RGB:

    File Test C3

    Back to the Original Issue:

    I hope you can help me out with the selection, my goal is that whenever you select or add selection to an object is to set a random color but unfortunately I'm not smart enough to solve this.

    Thanks ahead for any help!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • blackhornettechnologies.com/Construct3Stuff/Samples/SetColor.zip

    When in doubt, isolate it out (rhyme wasn't intentional).

  • rgba does take values in a 0-100 range, where 100 corresponds to 100%. However it is not limited to this range - you can pass 255, but that corresponds to 255% red, as in 2.5x more red than you'd normally get. This may be why you are getting unexpected results when passing 255 to rgba: it works, but not like you are expecting it to.

    If you want to use a 0-255 range, then there is rgba255 and rgbex255, which work identically but take values in a 0-255 range, where 255 corresponds to 100%. Again you can pass higher values like 500, but that corresponds to boosting that channel to higher than 100%.

  • Ashley I always wanted to ask - why rgb() expression inverts the result? For example, rgb(0,10,255)=16714240 , which is #FF0A00 in hex. It should be #000AFF, why R and B values are swapped?

  • rgba does take values in a 0-100 range, where 100 corresponds to 100%. However it is not limited to this range - you can pass 255, but that corresponds to 255% red, as in 2.5x more red than you'd normally get.

    255% OH! it make sense but still... I get 99% of the time RED colors even when I use int random as you suggested and 0-100 so something must be wrong in my code and I have no clue how to fix it.

    Ashley Thanks for the reply it explains the 255 vs 100 limit! :)

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