SCOPE: Local and global scope restrict access to variables based on where the variable was created.

  • Click Run and try to play the game. This is all of the code for the game you saw in Activity 2! All but one line.
  • "local variable 'score' referenced before assignment" means the program thinks score is local to the function.
  • score is local to the main code outside the function! To change score in the function we need to make it global.
  • In , add Global Variable inside the collision event and change the variable to score.

To navigate the page using the TAB key, first press ESC to exit the code editor.

# THIS ACTIVITY IS IN PREVIEW ONLY MODE
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)