#ifdef DEBUG preprocessor

I saw that this preprocessor is used in the PlayCanvas engine.
Would be great if it could be supported also in our scripts, like:

// #ifdef DEBUG
console.log('my debug message');
// #endif

This way we can clean the production code while keeping the developing smoother.

1 Like

it’s too easy to implement by developer oneself, I guess.

Especially, if you use only engine without Editor.

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

And then, check

if (getParameterByName("debug")) console.log();

Oh, I got you wrong.

But as long as you use project management tools, it should provide this functionality.
For instance - https://www.npmjs.com/package/preprocessor

Not sure how should I use them when publishing from the editor.

The main feature request here is about the editor. When I publish on their server I’d like to see all my debug logs removed from the sources. This way the game is faster, smaller and a bit safer from hacking or reverse engineering.

1 Like

Using the above function, I added this to a singleton script to reduce console spam:

if(getParameterByName("debug")) {
    this.app.__debug = true;
    console.log("ENTERING DEBUG MODE");
}

And, then the following into my other scripts:

var debug = this.app.__debug;
if(debug) console.log("Debug only string");

Some developers use a post processing script with the REST API to download the build without minification and use comment blocks to strip out blocks.