Water Use Calculator

Matching Things Up

Now that you’ve got the water amounts in a list, you’re going to put the sprite names in another list. Since the sprite names and the water amounts are related to each other, you’ll be using the same counter variable to keep track of which list item you’re on in both lists.

Make another list and call it Sprites.

Add two items to the list: Tap and Toilet. Make sure that what you type is exactly the same as the names of the Tap and Toilet sprites!

Once you’re done adding things to the list, hide it from the stage.

Now look at your script with the loops and find the two go to blocks that make the talking sprite move to the Tap and the Toilet sprites.

gotoTap

Just like you did before, drag an item block into each one — it doesn’t look like you can place something else into the box, but you can! Give it a try.

gotoitem1ofSprites

Your code should look like this now:

gotoitem1ofSpritesmove45stepsrepeatitem1ofWaterAmountsmove20stepsstampwait0.5secondsgotoitem2ofSpritesmove45stepsrepeatitem2ofWaterAmountsmove20stepsstampwait0.5seconds

Do you see that you are now using the same index to select the sprite name from a list and the matching water amount from the other list? This is the perfect opportunity to use a variable. Let’s do that now!

Create a new variable called counter.

At the start of the program, set the value of counter to 0:

whenclickedsetcounterto0

Drag the counter block into the four blocks where you get an item from a list, in place of the numbers 1 and 2.

gotoitemcounterofSprites
repeatitemcounterofWaterAmounts

One thing is still missing: the value of counter is 0 at the moment. You need to set it to the correct value before you use it each time. To do this, you will add 1. This is also known as incrementing.

Add in two change counter by 1 blocks into your code so that it looks like this:

changecounterby1gotoitemcounterofSpritesmove45stepsrepeatitemcounterofWaterAmountsmove20stepsstampwait0.5secondschangecounterby1gotoitemcounterofSpritesmove45stepsrepeatitemcounterofWaterAmountsmove20stepsstampwait0.5seconds

Run your code to check that everything is still working as it should!

Here is what the full program should look like by now:

whenclickedsetcounterto0eraseallgotox:0y:0settotalWaterto0setsizeto80%switchcostumetomonkey-aaskHow many times do you flush the toilet each week?andwaitsetflushestoanswerchangetotalWaterbyflushes*6askHow many minutes do you usually spend in the shower?andwaitsetshowerMinutestoansweraskHow many showers do you have per week?andwaitsetshowerstoanswerchangetotalWaterbyshowers*showerMinutes*7sayYou use...for2secondssayjointotalWater litres of water per week!for5secondssayHow about brushing your teeth?for2secondssayIt can be tempting to leave the tap running while you brush. But did you know...for4secondssay...a running tap loses 6 litres of water per minute?for3secondsswitchcostumetoglass water-asetsizeto35%changecounterby1gotoitemcounterofSpritesmove45stepsrepeatitemcounterofWaterAmountsmove20stepsstampwait0.5secondschangecounterby1gotoitemcounterofSpritesmove45stepsrepeatitemcounterofWaterAmountsmove20stepsstampwait0.5seconds

In the next step you will learn how to make your code even shorter with another clever loop!