Plan out your code - Use pseudo-code!

What is Pseudo-code?

Pseudo-code does not obey the syntax rules of any particular programming language. It is written by you in any way you like and is not meant to be compiled. It allows you to focus on your desired algorithm's logic instead of focusing on the actual syntax.

There are many different ways to solve a problem, and pseudo-code is here to help! It is simply a blueprint of your problem divided into its smallest pieces. It allows you to rearrange the order of these pieces to make sense for the final algorithm and plan out in which order you should implement them.

Pseudo-code is always written as a comment in the script. To comment out a line, you can use ‘// ’ at the beginning of the line. If you wish to comment out a block of code, you can do this by inserting ‘/* ‘ at the beginning of the block and ‘ */’ at its end. This way, the commented code will be ignored entirely by the compiler.

Example time!

Let’s say you have a laser attack, which you fire by pressing the ‘Space’ button. If your laser touches an enemy, the enemy gets destroyed. How do you write this down in pseudo-code?

You can end up with something like this:

But when you think it through once again, you might notice that you are not destroying the laser itself. So you insert another line in your pseudo-code so that you won’t forget when implementing it… and maybe add some score points for the player?

And that is it! Now you have broken down the problem to each step and can now start implementing your mechanic!

I hope I have explained the usefulness of writing down your pseudo-code. I do this pretty much always when I need to implement a more complex mechanic as I end up with fewer problems in the end.

But that is it for now, thank you for reading and feel free to follow me for more articles - and as always, good luck and see you next time!

Aspiring and eager beginner Unity developer