top of page

Legibility

Optimising Code Efficiency

- BRIEF - 


"Modern Solutions for Medieval Problems" is an FPS project I am in the process of developing. During the trialling period of implementing enemy behaviour, the variable declarations had become “spaghetti code”.

​

What Needed Fixing:

  • Reassess naming conventions of variables

  • Organise related variables

  • Enhance readability of code

  • Enhance the inspector view and interaction of variables within the engine

​

- ASSESSING THE VARIABLES - 

 

The starting state of variable names were OK barring some variables that could have more applicable titles for their purpose. Going over these, the regularHit and criticalHit variables were changed to defaultHitAnimationValue and criticalHitAnimationValue to represent the amount of damage it has to receive in order to play the respective hit animation. Several Boolean variables missed “is” statuses at the beginning of names. This was an easy update which helps the readability of shorthand coding throughout the script.

Variables_1.png
Variables_1.png

Old Variable Format

- ORGANISING, CATEGORISING & COMMENTING - 

 

Through the development process several variables had been implemented in easy to reach locations for quick access during testing, but were not moved to better locations after having been committed to. By implementing headers, I could categorise the core components of the enemy script and therefore organise the related variables together for both code readability and better organised inspector views. In order for my code comments to not be distracting and make the code look too busy, I tabbed the comments out to an equal distance to keep them structured and prevent them obscuring the code. Private variables required fewer comments, so an overall comment is located above related groups of private variables. The final 3 variables exist for other scripts to access and did not need to be visible on the inspector window. This led to unnecessary clutter which was easily rectified by adding the [HideInInspector] line above each variable.

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

 

 

One issue I encountered, stemmed from too many variables being shown in the editor – it still appeared to be messy and confusing in the inspector of the engine. My solution to this was to serialise the categories into a class with sub properties, emulating the effects of a dropdown box within the inspector window. This minimised the size of the overall inspector window when viewing variables was not required. Groups of variables could be displayed as necessary by clicking the dropdown arrow.

 

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

​

 

 

​
 

​

Variables_2.png
Inspector_3.png
Inspector_1.png
Inspector_2.png

New Code as Visible in the Inspector

New Structure with Headings and Ordered Comments

Inspector After Opening Each Sub-Object

Final Code as Visible in the Inspector

- RESULT -

 

The final result was a much more user-friendly, intuitive and informative script that would be easier to understand if accessed by individuals unfamiliar to the project. Understanding the variable purpose is much easier for a coder and the engine inspector window appears much more logical/ approachable to anybody working with the assets.

​

​

Variables_3.1.png
Variables_3.2.png

Final Code

bottom of page