I'm not sure how to explain this, and it is REALLY bothering me. It is messing up so much of my code. Anyway, here is basically what it is. Assume I have a variable that holds a struct with some values, say default settings:
var DefaultValues = {
username: "cakeisajoke",
this: "is some",
default: {
data: 483
},
lives: 3,
playerX: 0,
playerY: 0
}
In my code, I use this variable as a "template", so I can reset my game easier. Like this:
var GameValues = DefaultValues;
Okay, so that makes sense so far. Now, let's say the player loses lives:
GameValues.lives--;
Or, the player moves some:
GameValues.playerX += 20;
GameValues.playerY -= 10;
So, now my GameValues is changed, and I set the game to this. But, then the player fails, and gets a game over. If he wants to play again, all I have to do is reset the GameValues variable to the defaults:
GameValues = DefaultValues;
And, as far as I am concerned, this should just set GameValues to DefaultValues, right? But, it doesn't. For some reason, GameValues and DefaultValues now have the same values, when they shouldn't. For example, DefaultValues is now 0, instead of what is was originally, 1.
Why is it doing this? I have looked, and looked again, and I am NOT setting DefaultValues anywhere in the code except for that initial struct.
"I used this and default as an example, I know that I can't actually use them since they are reserved"