Skip to content

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.

General Formatting Guidelines

Macros

  • Macros are named in ALL_UPPER_CASE.
  • These are constants associated with an object and are potentially accessible from outside the object.

Local Constants

  • 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.

Enums

  • Enum constants follow the ALL_UPPER_CASE naming convention.
  • Enums comprise sets of framework-level constants, not tied to any specific object.

Variables

  • Variables use the all_lower_case naming format.
  • Local variables begin with an underscore (_all_lower), except for loop counters.
  • Object variable definitions use UpperCamelCase.

Functions

  • 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.

Method Variables (OOP Methods)

  • 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 to scr_ scripts.

Other Library Content

  • 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 and bgm_ for background music.
  • Other prefixes are used as applicable.

Code Writing

Parentheses

  • Parentheses are omitted except where they are strictly necessary.

Ternary Operator

  • Simple conditions replace if-else constructs with the ternary operator.

Guard Statements

  • An early exit is preferred wherever feasible.
  • The keyword exit is used instead of return when no formal value is returned.