Debugging using the console

Hi everyone! Answering a recent post has reminded me that a lot of users don't understand how powerful the console is and how you can use it to better understand what makes your game tick, so I decided to extract that part of the answer into its own post.

For anyone who doesn't know, when you're playing the game you can hit F8 to open the developer console, which allows you to run JS code immediately. You can use this to trace source code, check that a function works as expected, find out what values are held in a particular object at the time etc.

Let's say I have a fairy on my map that fully recovers the party (and has no other event command in it), and I want to know exactly what that's doing due to plugins that might affect it. The event's ID is 1. If I open the console, I can do this:

1595928354568.png


Then I can open up that object (the little arrow pointing right) and see the properties/functions it has access to:

1595928361676.png


If you scroll down and open "__proto__" you can see the details of its parent class:

1595928368060.png


One of these is "page", which contains the event code:

1595928374436.png


This is where you need to know a bit about the interpreter and event codes, but since we only have one command, it's obvious that the 0 element in "list" is our "Recover All" meaning that command has a code of 314. From there, you can open up rpg_objects.js and look up command314:

1595928386215.png


Now that we know it's calling the recoverAll function, we can enter that in the console on an actor to see what it does (if you enter a function name without the (), it'll show you the function itself:

1595928393226.png


Then click the f () { part to be taken to the actual source that it's referring to:

1595928402397.png


So here we can see that the "most recent" version of the function is in YEP_BattleEngineCore.js, and you can see from there what changes the overwrite has made.

This is invaluable for debugging, and can often show up the sources of bugs way more easily than trawling through the individual js files will.

Let me know if you have any comments or questions about this!
Thank you so much! I've always been confused about how to use the console. You've made it clear! I'm studying JS too so this'll come in handy. 🙏
Have you used the debugger to troubleshoot issues in RM before? Breakpoints etc.
Personally I haven't because usually the problems are quite obvious (eg: something dumb lol) but might be useful
Have you used the debugger to troubleshoot issues in RM before? Breakpoints etc.
Personally I haven't because usually the problems are quite obvious (eg: something dumb lol) but might be useful

I haven't tried it yet but next time I come across a tricky issue I'm gonna give it a shot.

Edit: Just had a play with it and it's actually really good. I may end up using this more often.
I haven't tried it yet but next time I come across a tricky issue I'm gonna give it a shot.

Edit: Just had a play with it and it's actually really good. I may end up using this more often.

I used to use a ton of 'console.log(variable)' to debug issues, but I have been using the actual debugger and break points lately and it is so much better.
I still use console.log a lot when debugging stuff with Yanfly's notetags for people, I think that's probably quicker than finding the line to set a breakpoint at.
Have you used the debugger to troubleshoot issues in RM before? Breakpoints etc.
Personally I haven't because usually the problems are quite obvious (eg: something dumb lol) but might be useful
I've used the debugger quite a bit when trying to figure out why something isn't working correctly. I strongly recommend it.

Supposedly there's also some way to link VSCode to the game so you can set breakpoints right in VSCode, but I haven't figured out a way to do that yet.

Original thread: https://forums.rpgmakerweb.com/threads/debugging-using-the-console.124626/