Link to the project or level: Game Lab - Code.org
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.
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
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:
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
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