How do you keep classes out of global scope, but allow other scripts to use them?

0 favourites
  • 2 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I want to make most of my game in JS, but also prevent players from seeing my game's functions in the console, which means I want to use globalThis sparingly.

    For example, I have a Player class which is applied to my Player object type using setInstanceClass(). Since createInstance() doesn't take any constructor arguments, I made a static function called create() to allow me to add properties to the instance after it gets created.

    The problem with this is that the Player class is global, so a player could easily go into the console and type Player.create() to create a new player object.

    However, I'm not sure how I would go about this while also letting the rest of my code access these functions.

    The only potential solution I've found wraps an IIFE around the Player class so that it's locked away from global scope, but now this means I can only access this class from within the IIFE.

    What's the best way to solve this?

    P.S: It looks like runtime is required to do anything with your game's code. Is this fact alone enough to solve this problem?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • There's no point trying to hide things from the console. If the user knows how to use a debugger, they can access everything anyway. Don't worry about it. Script minification is a much more effective barrier to stop people snooping in your code, but it's not bulletproof, and nothing is, unless you want to spend all your time in a DRM arms race.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)