# Why can't we randomize tint?

**URL:** <https://forum.code.org/t/why-cant-we-randomize-tint/39675>\
**Category:** Coding and Debugging Help\
**Created:** [August 16, 2024, 8:37pm UTC](https://forum.code.org/t/why-cant-we-randomize-tint/39675 "2024-08-16T20:37:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfranksa.sh](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@jfranksa.sh](https://forum.code.org/u/jfranksa.sh)\
**Post date:** [August 16, 2024, 8:37pm UTC](https://forum.code.org/t/why-cant-we-randomize-tint/39675/1 "2024-08-16T20:37:58Z")

</div>

**Link to the project or level:** [Game Lab - Code.org](https://studio.code.org/projects/gamelab/OR-t4ps7Rg9DxKqLaYubiLLELU4AC_5zxxPB2ZzNSnU)  
**What I expect to happen:** Starting on line 32 there is a conditional that changes the tint of the flower sprite when the bottle sprite is clicked. Student wants to randomize the color change by giving the tint a random value in RGB.  
**What actually happens:** No change occurs when the bottle sprite is clicked.  
**What I’ve tried:** Tint works when using a color name or a not randomized RGB. Using blocks removes the quotation marks. They tried manually typing the quotation marks back in. Is there something about the tint parameter that can’t be randomized with RGB? According to the guides, it should work fine. But we can’t figure it out.

Thank you for your time.

---

<div class="post-metadata">

**Author:** ![varrience](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/varrience/32/8042_2.png) [@varrience](https://forum.code.org/u/varrience)\
**Post date:** [August 19, 2024, 8:30pm UTC](https://forum.code.org/t/why-cant-we-randomize-tint/39675/2 "2024-08-19T20:30:52Z")

</div>

Greetings @jfranksa.sh,

your issue pertains to how your parsing string literals

> Problem

the interpreter that handles tint needs a value passed to it or a number type that can be read as an argument

> Example

```auto
plant.tint = "rgb(randomNumber(0, 255), randomNumber(0, 255), randomNumber(0, 255))";

```

_randomNumber_ won’t pass a number to the argument so it will read it **literally** rather than executing and procuring a value like it usually does which would be an int in the specified range

> Resolution

concatenate randomNumber functions to be executed before being put into the string so correct values are passed through each time

Here’s an example:

```auto
plant.tint = "rgb(" + randomNumber(0, 255) + "," + randomNumber(0, 255) + "," + randomNumber(0, 255) + ")";

```

this should solve your problem but it looks kind of long doesn’t it? well why not assign these values to an rgb array before putting them in like this

```auto
var colors = [];
for(var i = 0; i < 3; i++){colors.push(randomNumber(0,255))}
plant.tint = "rgb("+colors.join(",")+")";

```

though this is just one way of solving it since there are many other color formats you can use if you really want to hope this helps

P.S.  
if your currently looking for a way to detect one mouse press instead of multiple make sure you check for `mouseWentDown("leftButton")` which will prevent the click from executing multiple times

# Varrience
