Hello friends! Continuing with the Ultimate Guide series Godot Engine. In today's article I will share with you about Godot Engine's GDScript. The article includes 2 parts: Basic GDScript and Object Orientation in GDScript. Before getting into part 1, let's start with a brief understanding of GDScript!
Join the channel Telegram belong to AnonyViet 👉 Link 👈 |
BRIEF ABOUT GDSCRIPT
GDScript is a high-level programming language. It uses similar syntax to Python (blocks are based on indentation and many keywords are similar). It is optimized and tightly integrated with Godot Engine, allowing great flexibility for creating and integrating game content. If you are familiar with Python, coding with GDScript is extremely easy!
BASIC GDSCRIPT
1. Structure of a script.gd
extends Node # Khai báo kế thừa. Phải kế thừa đúng tên lớp (tên Node) mà bạn sử dụng.
|
2. BASIC GDSCRIPT
Main functions on GDScript
extends Node
|
Debug print command on Console window
func _ready():
|
Data types, variables, constants and declarations
Data types on GDScript are similar to those on Python, with two types: primitive types (without capitalizing the first letter) and class types (with the first letter capitalized).
extends Node
|
Conditional structure IF…THEN…ELSE
func _ready():
|
Match structure
func _ready():
|
For loop
func _ready():
|
While loop
func _ready():
|
OBJECT ORIENTATION IN GDSCRIPT
Creating and using classes are two essential tasks in object-oriented programming. Below is the formula for creating and using the class on GDScript.
Create class
Build properties (variables) and methods (initialization functions for objects)
class Math: #tên lớp
|
Use class (create object corresponding to class)
#var
|
In addition, we can also use classes using inheritance with extends. Note: If you create a class that inherits the default class in Godot, there is script uses class must be assigned Node has the same type as the class you previously instantiated and used.
In today's article, I introduced and shared with you basic GDScript on Godot Engine. If you have any questions, please leave a comment or suggestion! To better understand, you can refer to the basic videos at https://www.youtube.com/playlist?list=PLOk8LhtEwUVn8e3RUfk-rX_RB3f9_ulYg. Thank you for following the article! ?