This guide establishes consistent coding standards across all programming languages used in the GCT2 project (Python, C++, Lua, JavaScript) to ensure readability, maintainability, and collaboration.
Use snake_case (lowercase words separated by underscores) for all variable names, function names, and methods within classes or modules. This applies to local variables and private/protected members where applicable.
Examples:
- Python:
user_input,process_data() - C++:
int entity_id;,void get_player_coords(); - Lua:
local current_vehicle,function update_status() - JavaScript:
var player_health;,function calculate_distance() {}
Use PascalCase (first letter of each word capitalized) for class names, struct names, enums, and custom types.
Examples:
- Python:
class PlayerManager: - C++:
class VehicleControl;,enum CommandType; - Lua: (N/A, Lua is not object-oriented in the same way, but applies to constructors or factory functions like
Player:new()) - JavaScript:
class GameState;
For global variables registered through specific GCT2 mechanisms (e.g., Lua's RegisterGlobalVariable), use PascalCase. This clearly distinguishes them as globally accessible project-specific entities.
Examples:
- Python:
GCT.Globals.register("VehicleSmokeLevel", 9.0) - C++:
GCT2::Global::Register("ThisScriptStatus", "active"); - Lua (GCT2):
RegisterGlobalVariable("PlayerVehicleHandle", 0.0) - JavaScript:
global.register("Friend name", "Ethan Hunt");
For functions provided by the core GCT2 framework or its specific APIs, use PascalCase (first word lowercase, subsequent words capitalized).
Examples:
GetGCTFolder()GetGCTStringVersion()
When calling native functions from the game engine or underlying system (e.g., RAGE Native functions, Windows API), follow their established naming convention. Often, these are UPPER_SNAKE_CASE. Do not rename or wrap them merely for stylistic reasons unless creating a clear, intention-revealing abstraction.
Examples:
PLAYER.PLAYER_PED_ID()(Lua)ENTITY.GET_ENTITY_FORWARD_VECTOR(entity)(Python)APPLY_DAMAGE_TO_PED(ped, damageAmount, p2, p3, weaponType)(JavaScript)
Use UPPER_SNAKE_CASE (all uppercase words separated by underscores) for constants, which are values that do not change during program execution.
Examples:
- Python:
MAX_PLAYERS = 32 - C++:
const int MAX_RETRIES = 5; - Lua:
local DEFAULT_TIMEOUT_MS = 1000 - JavaScript:
const PI = 3.14159;
All source code files (.py, .cpp, .h, .lua, .js, etc.) should use snake_case.
Examples:
player_commands.luavehicle_control.cppnetwork_utils.pyui_elements.js
Use 4 spaces for indentation. Never use tabs. Configure your editor accordingly.
- Place a single space around binary operators (
=,+,-,*,/,==,!=,<,>,<=,>=,and,or,not). - Place a single space after commas in lists, arguments, and table/array declarations.
- Avoid trailing whitespace at the end of lines.
Aim for a maximum line length of 120 characters. Break longer lines into multiple lines for readability.
Prefer using trailing commas in multi-line lists, arrays, or table definitions where supported by the language. This reduces diff noise and makes reordering or adding elements cleaner.