A simple debugging trick

  • I did a quick Google search to see if this had already been suggested somewhere but didn't find anything...

    The game flow of my current project has gotten a bit complicated as I transition from my puzzle, to a scoring popup, and then on to the next puzzle. I was having strange issues and to help me find the problem I came up with the following idea:

    1. I added an array to my layout and called it "array_debug".

    2. Then I created an event that PUSHED a string value to my new array.

    3. I pasted this event in each of my main code Groups, and in each Function that wasn't part of a loop. (Then I changed the value I was pushing to represent the Group or Function name.)

    4. When I run my game in Debug Mode I can then look at array_debug to follow my event flow.

    What I EXPECTED to see was something like this:

    Initialize Group

    Setup Group

    Create Sprites Function

    Game Group

    Scoreboard Group

    Final Score Group

    What I ACTUALLY saw was this:

    Initialize Group

    Setup Group

    Create Sprites Function

    Game Group

    Scoreboard Group

    Scoreboard Group

    Scoreboard Group

    Scoreboard Group

    Scoreboard Group

    Scoreboard Group

    Scoreboard Group

    Scoreboard Group

    Scoreboard Group

    Scoreboard Group

    Scoreboard Group

    ...

    My scoreboard group was supposed to execute once and then exit, but I forgot to deactivate the group so it was running over and over again. Now I'm paranoid about other places where I'm looping through unnecessary code that might be slowing my game down. This trick should help me find those sorts of problems.

    EDIT: This trick can also be done by logging events to the browser console, but to be honest I haven't looked into how to do that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Logging in browser console is actually much easier -

    simply add "Browser Log" action in key events. You can include any important information there - variables values, behavior states etc.

    Then run the project, press F12 and select Console tab.

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