-
Notifications
You must be signed in to change notification settings - Fork 11
Style Guide
This page documents what I believe to be the proper way to write code for Reactor 3. I highly recommend following the below specifications to make it easier for people to interpret your code, and also heighten the chance of getting your additions into the main repo.
Variables that are local to one function and aren't being returned can be named as you like. I typically put an underscore below these variables to indicate that they are going to be thrown out instead of returned.
Variables that are being returned should have names that indicate the data type being returned. Something like items or speed will work, as they both clearly explain what is being returned (with speed not so much, but anyone who has experience with game development would know it's an integer.)
Function names should state exactly what the function accomplishes. While change_character_name_to is exact, it is unnecessary to state that the method applies to a character. Instead, the name of the file it resides in gives proper context to what it modifies. life.change_name_to is ideal.
File names should be simple and clear. life, items, and maps all give enough context to the functions they contain.
Arguments should be named specifically and make sense in the context of the function's name. If the name of your function is change_item_speed, then we know two things:
- The item is not in a player's inventory, so we should reference the item directly since it has no inventory ID.
- An
intshould be passed in.
The end result may look like change_item_speed(item,value). value could be changed to something more specific, but with the function's name taken into account, it is perfectly fine.
If the function is modifying an item's properties inside of a player's inventory, then change_item_weight(life, id) makes enough sense when it pops up in your IDE's code completion window. id might seem a bit vague, but if you have a working knowledge of the way characters track items, it makes sense: Characters store items in a dictionary, with each key being an ID of an object. The above function could fetch the item directly by calling life['inventory'][str(id)]. Please note that you should always convert the ID to a string unless you are 100% sure a string is being passed in. This is arguably the only downside to handling items this way.