2

I want to prevent cheating on my game by not letting console user change variables through the console, is there a way to do this.

1 Answers1

2

The easiest way would be to enclose your whole script into an IIFE. For example, change:

var points = 0;
// do stuff with points

to

(() => {
  var points = 0;
  // do stuff with points
})();

This way, it will be markably more difficult to change points from outside by the user - but it won't be completely impossible.

(Also make sure not to store any variables on the window - define them inside closures instead, like above)

Fundamentally, all code executed user-side is untrustworthy. The only way to be sure that something is legitimate is to do all the verifications on the server instead.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320