Allerious Posted May 6, 2019 Share Posted May 6, 2019 It's my understanding that we need to run this line of code at the beginning of the script (see link) so that the GamePiece variables are global and thus allowing the updateGameArea() function to use them. If i remove this code the updateGameArea() still runs those objects as though they're global. Surely they're local to the startGame() function by removing this first line of code? var redGamePiece, blueGamePiece, yellowGamePiece; https://www.w3schools.com/graphics/tryit.asp?filename=trygame_component_more Link to comment Share on other sites More sharing options...
dsonesuk Posted May 6, 2019 Share Posted May 6, 2019 (edited) If you declare the function variables without 'var' the variable becomes automatically global, with var it is local to the function only. Edited May 6, 2019 by dsonesuk Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now