💡

GD Script: A Beginner's Guide

Jun 9, 2024

GD Script: A Beginner's Guide

Introduction

  • GD Script: High-level, object-oriented, imperative, gradually-typed programming language.
  • Syntax similar to Python, built specifically for Godot.
  • Tutorial covers variables, conditionals, input, inheritance, dictionaries, signals, and more.
  • Suitable for both beginners and experienced programmers.
  • Not an introduction to Godot; start with a beginner video if unfamiliar.

Basic Code Structure

  • Creating Scripts: Attach scripts to nodes in Godot (e.g., main.gd for the main scene).
  • Main Function: Use the _ready() function as the entry point for running code when the node appears in the scene.
  • Printing Messages: Use print() function to output messages to the console.
  • Running the Game: Press F5, select the current scene, and press F8 to stop._

Syntax Essentials

  • Code blocks are defined by indentation, similar to Python; no semicolons needed.
  • Case-sensitive: print vs Print.
  • Use _ready() function to execute code when a node enters the scene tree.
  • Use pass keyword as a placeholder._

Modifying Nodes

  • Nodes can be accessed and modified using scripts (e.g., change label text, modulate color).
  • Use $NodeName to reference nodes.
  • Use node.property to modify properties.

Handling Input

  • Input Mapping: Define actions in Project Settings > Input Map (e.g., bind spacebar to action).
  • Input Function: Use _input(event) function to handle input events (e.g., event.is_action_pressed(_