Console Logging: Technique and Best Practices

0 favourites
  • 5 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • Hello Forum,

    I'm still new to game development and Construct 3 and I'm only now learning to appreciate the importance of logging in the console to debug. Does anybody have any effective strategies or practices for logging? Do you just use the basic Browser -> Log action? Do you only add those when you are trying to debug a specific issue in a specific set of events, or do you consistently add logging events to everything? Any cool functions anybody has made to make the logging more robust and easily repeatable across different events? I've been using the CurrentEventSheetName and CurrentEventSheetNumber, but I don't see any way to easily log the Event Group location except by manually typing in the text every time.

  • I use console very rarely only when I need to check something in mobile game preview. Construct3 has a great mode to run in the debug mode, there you can see variables, arrays and much more, you are not programming in Python to constantly output something to the console. This is my humble opinion.

  • Logging stuff can be useful to debug things but I only use the browser console for JavaScript stuff. When just logging stuff with events I just append stuff to a textbox, and even then it’s only temporary.

    You’ll have to indicate the location when you log manually. Usually it’s not a big deal but there isn’t an automated way to get the location when you log with events or JavaScript.

    Now if you made an addon to do the logging it can know the location on the event sheet it was called from. It seemed possible in C2’s addon sdk but no one ever used it. You’d need to investigate c3’s addon sdk to still see if you can do that. But it’s easier and faster to just manually specify the location than to make a plug-in to help with that.

  • I use console logging all the time! In many cases it's the fastest and most efficient method of debugging in Construct.

    Any cool functions anybody has made to make the logging more robust and easily repeatable across different events?

    I have a _LOG function, but only so that I could easily disable all logging when I prepare a release build.

    ChatGPT gave me this function that allows to override the default implementation of "Browser Log" action and it works.

    (function() {
     // Save the original console.log method
     const originalLog = console.log;
    
     // Override console.log with your custom implementation
     console.log = function(...args) {
     // Add additional information, such as a timestamp
     const timestamp = new Date().toISOString();
     // Call the original console.log with modified arguments
     originalLog(`[${timestamp}]`, ...args);
     };
    })();

    However, I don't think it would be possible to include an event sheet name or event number, because these expressions are not available in scripting.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I made an addon!

    dropbox.com/scl/fi/delsw6e272u78m4qhgj1c/ConsoleLogger_addon_dop2000.zip

    It also allows to disable console logging in the entire project.

    Be aware that it will probably stop working when SDK1 is retired.

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