-
Notifications
You must be signed in to change notification settings - Fork 16
Extra: Code Guidelines
Triangly edited this page Sep 6, 2024
·
1 revision
Orbinaut Framework 2 has its own coding guidelines (somewhat based on conventions used in the GameMaker manual) to keep the code clean and consistent.
You are not forced to follow them.
- Macros are named in
ALL_UPPER_CASE. - These are constants associated with an object and are potentially accessible from outside the object.
- Local constants are also written in
ALL_UPPER_CASE. - These are constants specific to a script, function, or event and are used only within that scope.
- Enum constants follow the
ALL_UPPER_CASEnaming convention. - Enums comprise sets of framework-level constants, not tied to any specific object.
- Variables use the
all_lower_casenaming format. - Local variables begin with an underscore (
_all_lower), except for loop counters. - Object variable definitions use
UpperCamelCase.
- Functions are named in
all_lower_case. - These functions are not bound to any specific object.
- Each function is placed in a script that shares the function’s name.
- For objects complex enough, scripts help organize functionality. Such functions are considered "private" and follow these guidelines:
- Function names begin with
scr_followed by the object name. Example:scr_player_movement_ground(). - Each function is positioned near the object to which it belongs.
- The directive
gml_pragma("forceinline");is used to enhance performance in YYC for functions executed every step.
- Function names begin with
- Method variables are named in
all_lower_case. - These are functions linked to a specific object, event, or function.
- If a method variable is associated with an object, it is initialised in the Create Event and starts with
m_followed by the object name. - If associated with an event or other function (i.e., a local method), it begins with
m_local_. - If there are too many such methods, they are grouped into a script named
m_+ a simple name of the object (e.g.,m_player). This script is placed near the object, similar toscr_scripts.
- All library content is named in
all_lower_case. - Sprites use the
spr_prefix. - Objects use the
obj_prefix. - Audio files use
sfx_for sound effects andbgm_for background music. - Other prefixes are used as applicable.
- Parentheses are omitted except where they are strictly necessary.
- Simple conditions replace if-else constructs with the ternary operator.
- An early exit is preferred wherever feasible.
- The keyword
exitis used instead ofreturnwhen no formal value is returned.