My focus in this question is making HTML5 games. The aim is to help reduce/prevent cheating.
If a variable in global scope held the score, for example var score = 0, then it’s really easy to cheat just by running javascript:void(score = 9999999999);.
But if I had something more like this:
(function() {
var score = 0;
// game logic here
})();
Is score accessible by anything outside the closure? Is there any way for the player to modify it and thus falsify their points?
Outside of that closure,
scoredoes not exist (or at least, thatscoredoesn’t).If you want to prevent cheaters, the only real way when the whole game runs on the client side is to recreate the game environment and user input on the server and validate that.
Otherwise, anyone can modify your client side code and send what they wish to your server.