Adding a Step Counter to Our Program

Adding a Step Counter to Our Program

Let's imagine that the Cat wants to know how many movements it makes when it is dancing.

This would work similarly to a pedometer that keeps track of how many steps you take each day.

We will create a variable called number of movements that will keep track of how many movements the cat makes.

To create the variable, follow these steps:

  1. Go to the Data blocks section of the Scripts tab
  2. Click the Make a Variable button
  3. Name the variable number of movements
  4. Tick the For this sprite only checkbox
  5. Click the OK button

We want to add 1 to this variable every time the Cat moves, using the change variable block Our Dancing Cat program is shown below.

How many change variable blocks should be added below and where do you think those blocks should be placed?


Two change variable blocks should be added to your Dancing Cat program and each of these should be placed after one of the move blocks, as shown below:


Click the stack of blocks and watch the number of movements variable's Stage monitor. Notice that the number of movements variable increases by 8 every time the Cat does its dance from start to finish.


Views
1 Total Views
1 Members Views
0 Public Views
Share on Social Networks
Share Link
Share by mail

Please login to share this webpage by email.