Gd Script
Gd Script
https://gd.tumeo.space/
Introduction to GDScript
1. Introduction to GDScript
• GDScript is a high-level, dynamically typed programming language
used to create games and applications within the Godot Engine.
• In GDScript, the for loop typically uses the range() function or iterates
over elements in a list, dictionary, or other iterable collections.
Example: Iterating Over a Range of
Numbers
for i in range(5):
print(i)
Example: Iterating Over an Array
var fruits = ["apple", "banana", "cherry"]
Expected result:
The product is: 46080
2.7 Match Statement
• The match statement in GDScript is similar to the switch statement in
other languages. It allows you to compare a variable against multiple
values and execute different code depending on the match.
Example:
var day = "Monday"
match day:
"Monday", "Wednesday", "Friday":
print("You have classes today.")
"Saturday", "Sunday":
print("It's the weekend!")
_:
print("It's a regular day.")
Challenge:
Defines a variable command with values like "start", "stop", or "pause".
Uses a match statement to print appropriate actions based on the value
of command.
Intermediate GDScript
Concepts
1. Introduction
• This lesson will introduce functions, arrays, dictionaries, and object-
oriented programming (OOP) principles in GDScript.
Learning Objectives:
• Understand and create functions in GDScript.
• Work with arrays and dictionaries to manage collections of data.
• Explore basic object-oriented programming concepts like classes and
inheritance.
2. Intermediate Concepts in
GDScript
2.1 Functions
• Functions are reusable blocks of code that perform a specific task.
They help organize your code and make it more modular and
readable.
Example:
func greet(name):
print("Hello, " + name + "!")
greet("Godot")
Challenge:
1. Write a function called add_numbers that takes two arguments and
returns their sum.
2. Write a function is_even that takes an integer and returns true if it's
even, and false if it's odd.
2.2 Arrays
• Arrays are collections of elements that can be accessed by their index.
They are useful for storing lists of items.
Examples:
var fruits = ["apple", "banana", "cherry"]
func take_damage(amount):
health -= amount
if health <= 0:
print(name + " is dead.")
func take_damage(amount):
health -= amount
if health <= 0:
print("Enemy defeated.")
func use_special():
print("Boss uses " + special_attack + "!")
Challenge:
Create a base class Vehicle with properties speed and color.
Create a subclass Car that inherits from Vehicle and adds a new
property make.
Create an instance of Car and print its properties.
Challenge:
Defines a class Character with properties like name and level.
Defines a subclass Wizard that adds a property mana and a method
cast_spell.
Creates a Wizard object and demonstrates casting a spell.
Remember: