Pseudocode: Simple, Yet Effective

Liberty Depriest
3 min readJun 22, 2022

--

C# script

Take a look at this script. At first glance, can you tell what it’s about? If you’re an experienced programmer, then probably… but for beginners, it might be a little difficult to look at.

No matter if you’re a beginner or pro, it’s best practice to incorporate pseudocode within your scripts.

What is pseudocode? It’s an explanation of your code in the form of comments. In C#, you type “//” before a comment. In Python, you type “#.” All languages understand the importance of pseudocode.

It also helps when other programmers have to take a look into your code. It makes development much faster if they understand its objective. (Be courteous!)

This is what gets executed:

So now we know that we have made a movement script! With this in mind, how can we improve the readability of our code?

I would focus mostly on the PlayerMovement method:

Here we added comments about the axes in the input manager. Now we know how we’re getting those!

Here we’re explaining the physics of the player. The rigidbody component can be modified in many ways. Here, we need to freeze rotations, increase drag, and angular drag to get the perfect settings. Our movement is also done in the last line!

Lastly, we’re capping the amount of jumps you can do (which is only one.) We explain how this logic works and why we need a new method called “onTriggerEnter.”

This amount of comments may be excessive, but it’s up to your judgement how you format them. You can explain line by line like here, but I prefer to make a paragraph-like comment before any code.

The use of pseudocode is an excellent way for beginners to understand programming. In this case, we used it as a way to explain code we already implemented. But you should definitely use pseudocode to plan out code in the future, like making a double jump feature:

And that’s it! Don’t be afraid of having to pseudocode too (trust me, once your script becomes thousands of lines long, you WILL need it!)

Have a great game-dev day!

--

--