Make the Light Repeat
Right now, the light only turns on and off once. To make the lamp continuously glow on and off, the fors loops will be placed inside a repeating while loop.
- Place both for loops inside a while loop. Indent the for loops to make them easier to tell apart from the while loop.
Keep Code Indented
To make your code easier to read, check that your code is indented like the block above. To indent your code:
- Tab to move a line forward.
- Ctrl / Cmd + Tab to move a line back.
- Run the game to see the light turn brighten and dim forever.
Troubleshooting Tips »
If you can’t see the brightness change over time:
- Make sure that
light.Brightness = currentBrightnessis between the do and end of your for loop.
- Check that
timeChangeis at least 1 or higher. Smaller numbers will make the brightness change faster, but be harder to see over time.
- Check that the first line of your for loop has two total commas separating the control variable, end value, and increment value.
Finished Project Sample
Download the finished project here.