Menu
CoddyTech

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: player2 is valid, 2player is not
  • A keyword such as var or func cannot be a name

Names are case-sensitive: score and Score are two different variables.

challenge icon

Challenge

Beginner

The three variables in the program are not named in snake_case, and the print() lines already use the snake_case names. Rename the variables:

  • PlayerName to player_name
  • coinCount to coin_count
  • IsOnline to is_online

Keep the values as they are and do not change the print() lines. The program prints:

Player: Ada
Coins: 120
Online: true

Try 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)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Online GDScript compiler