Como Manter Seu Projeto Organizado

1

Index

Tagged

Stats

3,424 visits, 4,638 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 24 Apr, 2015. Last updated 25 Feb, 2019

Step 3: Organizing your code

This is probably the most important part. If you keep your code messy and uncommented, you will often be lost in your own code, and will have a very hard time correcting bugs. Leaving a project for a month or so and coming back only to find a mess of a code, is one of the most frequent programmer's nightmare.

Commenting

The base to make any code organized in any programming language. Adding comments to describe what a piece of code do will save you from having to analyze your code every time you need to find something.

So let's say I have a bug in my game related to how my events react to the position of the player in the map. I can search for the bit of code that does that, or I can just read the comment:

You can also use comments to separate your global variables, and don't forget global and instance variables have a description section of their own.

For more information, check out the manual page about comments.

Groups

Separating your code into groups makes it easier to find the code you need as well. If you need to change something about how the player moves, you just need to open the "Movement" group and you are sure to find what you are looking for.

Furthermore, you can toggle a group active using events to create conditional blocks of code (e.g. a "Player Dies" group, that contains actions to perform when the player dies). You can also systematically deactivate groups to find where in your code is the error you are looking for.

For more information, check out the manual page for groups.

Common Events

You can create and attach multiple event sheets to the same layout. This can be useful when you have multiple layouts that use the same events.

For instance, in a platforming game, all levels have coins you need to collect, but only one level has lava that can kill you.

You can make the events for coin collecting in a "common" event sheet and attach it to your level's corresponding sheets (the ones we added a "$" symbol, remember?), and put the code for lava only in the event sheet for the level that needs it.

This is a practice that you should employ if you notice you have code you want to copy between sheets. Having multiple copies of the same code will cause any bug you encounter to have to be solved again and again on different event sheets.

For more information, check out the manual page for includes.

Conclusion

Organization in a project is often an overlooked aspect of it. You can't deny that being organized is an important part in any serious work, and it isn't any different when working on your game project.

With an organized project, you will no longer waste time trying to understand your own code, or trying to find that nasty bug. It will keep even a big project easy to manage, for you, or for an outsider looking at it.

  • 0 Comments

Want to leave a comment? Login or Register an account!