GameLab Scoring Capability


#1

Looking for a way to put code blocks together that allow my students to keep score in GameLab.


#2

In the Computer Science Discoveries curriculum, several lessons in Unit 3 build up and eventually have the student use a variable to keep score in this side-scroller game: https://studio.code.org/s/csd3/stage/16/puzzle/9

Here’s the gist:

  1. Create a variable to keep track of the score (var score = 0;)
  2. Use an “if” statement in your draw loop to constantly check if your scoring criteria is met (if x is touching y…)
  3. If that condition is met, increase your score variable by 1 (score = score + 1;)

Remember the score is tracked internally, so it’s invisible to the user. You may need to remind students to add blocks to display the score whenever the score is updated (use the “text” block).

For the bunny/carrot example linked above, here’s my code that would go near the bottom…
// when bunny touches carrot
// add 1 to score and put carrot back off screen
if (carrot.isTouching(bunny)) {
carrot.x = 400;
score = score+1;
carrot.y = randomNumber(200, 400);
}