Naming Conventions
Part of the Fundamentals section of Coddy's GDScript journey. Lesson 9 of 92.
Naming conventions are guidelines that make code easier to read. The Godot style guide writes variable names in snake_case: lowercase words separated by underscores, such as player_name or max_health.
Choose descriptive names that say what the value means:
# Bad naming
var isAlive = true # not snake_case
var a = 10
var b = "Hello"
# Good naming
var is_alive = true
var age = 10
var greeting = "Hello"Some rules are syntax, not style, and breaking them is an error:
- A name contains only letters, digits and underscores, so no spaces or hyphens
- A name cannot start with a digit:
player2is valid,2playeris not - A keyword such as
varorfunccannot be a name
Names are case-sensitive: score and Score are two different variables.
Challenge
BeginnerThe three variables in the program are not named in snake_case, and the print() lines already use the snake_case names. Rename the variables:
PlayerNametoplayer_namecoinCounttocoin_countIsOnlinetois_online
Keep the values as they are and do not change the print() lines. The program prints:
Player: Ada
Coins: 120
Online: trueTry it yourself
extends Node
func _ready():
# Rename these variables to snake_case
var PlayerName = "Ada"
var coinCount = 120
var IsOnline = true
# Don't change the lines below
print("Player: ", player_name)
print("Coins: ", coin_count)
print("Online: ", is_online)
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsInteger DivisionModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators10Functions
Declare a FunctionArgumentsReturnReturn TypesRecap - Sigma FunctionRecap - Validation FunctionDefault Values5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary OperatorPractice on your own: Online GDScript compiler