The Beast in the Castle Code Review

The Usefulness of Comments

Now, when writing your game, on of the easiest commands to overlook in terms of usefulness is *comment. At first glance, it doesn’t do anything other than hide a line, but when used well, it can make things a lot easier on you.

Let me be clear here, at some point, you’re going to want someone to read your code. Preferably, you’re going to want a few people to read your code. There are a lot of little errors which can creep in no matter how good you are that no amount of automated testing, nor regular beta testing will find.

So, for example, @iris did one thing I always love, which is to break down her *create commands into categories and label them. This one in particular jumped out at me:

*comment BEAST STUFF
*create withbeast false
*create beast 0
*create freaction 0
*create freactionshow 0

Why did this jump out? Well it jumped out because I saw one variable that I didn’t understand: freaction. My first though was free action? However, I wasn’t sure. That prompted me to do a quick search for it through the rest of her game, so that I could know what the variable was for, and I found seven instances of it being used, twice in *ifs, and five times in the same *choice. The choice was the obvious place to look:

[details=Code has been shortened to just the parts that matter.]```
[The PC first sees the Beast, then a few NPCs react, then this *choice shows up.]

You are…
*choice
#Terrified.
*set freaction +1
#Confused.
*set freaction +2
#Frozen.
*set freaction +3
#Angry.
*set freaction +4
#Fascinated.
*set freaction +5


Well, considering this is the only `*choice` where the stats change, and that the stat numbers are sequential, it's apparent that the specific numbers don't matter, but the choices do. Looking for context clues around the `*choice` I found it was the first time that the PC was reacting to the beast, which clued me in on what the variable was, that is the PC's `f`_irst_`reaction` to the Beast.

Now, obviously, this is a minor instance, but it's a good indicator of how even a few `*comment`s can really help someone read your code. Likewise anyone that's come back to a project after a few months can tell you that this can help _you_ read your own code too. However, that `*choice` brings up the first critique I have...

[[Return to the first post]](https://forum.choiceofgames.com/t/the-beast-in-the-castle-code-review/22238/2)
1 Like