Comments in Code

When working in collaboration with other people, when dealing with a large project, or even just for your own reference and debugging, leaving comments in your codes and scripts is very important. In GameMaker Studio 2 you have various mechanisms to help you leave notes and comments about code sections and even whole blocks of code that can be seen in the event list of the object that you are currently editing, and in this way you can leave notes to yourself and to your colleagues, or to explain a particularly tricky piece of code, or even just leave a reminder about what something does.

The first thing you can do is leave a short comment using // before the text. For example:

//initialize variables
sr = 10;
hp = 100;

You may also leave multi-line comments, to give credit, to omit a complete section of code for debugging, or even to explain the arguments of a script. For that you can use /* ... */ like this:

diff = angle_difference(angle1,angle2);

angle1 first direction in degrees, real
angle2 second direction in degrees, real

returns: difference of the given angles in degrees, -180 to 180
return ((((argument0 - argument1) mod 360) + 540) mod 360) - 180;

Finally, if you are writing custom scripts and want to have some control over how they are treated by the IDE (ie: have auto-complete or show the script arguments) then you should be writing your comments using JSDoc notation as explained here.