I have a student working on their video game for unit 3, lesson 28. They’re receiving the “Out of Scope” error message and I’m not sure where the issue is in the code. Would someone be able to assist?
Hi @csalinas,
There are a few things to causing errors in the game.
First, remember to declare variables only one time in the whole program. (I like this video as a good review of using variables). For example, this game has “var claw” both on line 5 as well as line 16. That what is causing this error. Because it is declared again in the if statement on line 16, it isn’t available to use in the other if statement. This is the out of scope error. However, if all variables are declared (using var) at the top of the program they are available throughout the program. I would also move the var machine to the top of the program. If you need it to be hidden, use the machine.visible = false and then change it to true when the space key is down.
Another thing to look at line 22. On one side of the equal, it is claw.velocityX but on the other it is claw.x. They should be the same on both sides.
Good luck!
~Michelle
This was awesome, thank you so much!