Simple way to prevent input from the console?

So I knew when I started making this game, using global variables would not be a good idea, but since I was wanting to build this asap without much thought into it, I chose to use the global variables so I could debug from the console. Now, many parts within the game depends on these variables, including other scripts. Without having to go back and rewrite all the code where I have these variables, is there just a simple way to disable input from the console?

Thanks in advance!

If I’m not mistaken, when the player goes into “play” mode, the variables won’t be visible along with any other development variables related to PlayCanvas. They’re only visible to you because you’re playing from the editor, in debug mode.

If you host your game to your own website then yes, this would be a problem that you’d have to look into, but if you host on either the PlayCanvas website itself or on itch.io for example then your variables are safe from view in the web console either way. It’s pretty common for game hosting websites to keep them out of sight of the player.

Sweet, thanks for the reply. It appears the objects that’s initialized do not show up, the global variables I still have access to, but if I set those variables, they dont affect the game. Thanks again!

1 Like

You can also scope them into an anonymous function.

eg

(function() {
var turn;
// More code, script code etc
})(); 

I did use that function, however, I’m still able to change that variable in the console. Here is the simple edit I made, and the results. Like I said earlier, I have a few of these throughout the app that other scripts depend on.

 
(function() {
var turn;
})(); 

Network.prototype.turn = function (data) {
    turn = turn;
    return turn;
};


turn2

As long as it’s not accessible from the published game, I can live with that. I plan on adding more characters which will make me upgrade, therefore I shouldn’t need to take it off of PC.

In the context that you posted, it be:

(function() {
var turn;

Network.prototype.turn = function (data) {
    turn = turn;
    return turn;
};

})();

Whether this works for you highly depends on where else you use the global variable. If it’s just this function, then this is fine.

Tbh, you be best off obfuscating using a tool like this https://obfuscator.io/

This makes it very very hard to edit the code and values in devtools.

1 Like

Yea I knew I’d have to go back and fix some things when I was putting it together. I have an IT background, but not in programming. This is just a game the wife and I like to play and if I can get away with hosting it out here and the published version can’t be manipulated this way, I’m ok with that. Thanks again for your help.

ok I’ll look into it, thanks again!