Help with Program Containing a list

The program I am trying to make is supposed to create 100 fireworks, place them in a list, and when you hit a it is suppose to explode. Can anyone look at my code and tell me why the one I created does not work. I am missing a fundamental part of arrays because this is the second or third time I have run into a program with arrays that does not work. Definitely does not help that I am the only teacher in my building using this platform. Your help is appreciated.

2 Likes

Hello!

Everywhere you are using the length of array block, you need to set the variable to Firework list in the drop down instead of just list. You also want to use the math block num - num to remove 1 from the index of each firework since arrays are indexed starting with position 0.

If you know the length of the array, then you can create a variable to keep track of it. Then use a for index from 0 to number loop to create each fire work. That way, you can just use the calculated index variable you get as part of the loop. Don’t forget to still minus one from the number of fireworks since we starting the count at 0.

As for the A button press, try removing the repeat 30 block since you already have a for loop going through every firework sprite in the list.

Here is the code with the changes:

Try messing around with the start effect block as well! https://makecode.com/_iDUdwh9yCVFf

2 Likes

You can get your repeat 30 block to work if you add a pause of 1ms between each iteration:

2 Likes