Hello friends! Continuing with the series The Ultimate Guide to Godot Engine. In today’s article, I will share with you about Godot Engine’s GDScript. The article consists of 2 parts: Basic GDScript and Object Oriented in GDScript. Before going to part 1, let’s start with a brief overview of GDScript!
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
A SUMMARY OF GDSCRIPT
GDScript is a high-level programming language. It uses the same syntax as Python (indent-based blocks and many similar keywords). It is optimized and tightly integrated with the Godot Engine, allowing great flexibility for creating and integrating game content. If you are familiar with Python, coding with GDScript is extremely easy!
GDSCRIPT BASIC FEMALE
1. Structuring 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. GDSCRIPT BASIC FEMALE
Main functions on GDScript
extends Node
|
Command to print Debug on the Console window
func _ready():
|
Data types, variables, constants and declarations
The data types on GDScript are similar to those in Python with two types: primitive types (without capital letters) and class types (with uppercase letters).
extends Node
|
Conditional structure IF…THEN…ELSE
func _ready():
|
Structure Match
func _ready():
|
For . loop
func _ready():
|
While loop
func _ready():
|
AUDIENCE IN GDSCRIPT
Creating and using classes are two essential tasks in object-oriented programming. Here is the recipe for creating and using the class on GDScript.
Create class
Construct properties (variables) and methods (object constructors)
class Math: #tên lớp
|
Using class (create object corresponding to class)
#var <tên biến file script> = preload("đường dẫn script")
|
In addition, we can also use the class by using inheritance with extends. Note: If you create a class that inherits the default class in Godot it is in script using class must be assigned to Node has the same type as the class you previously instantiated and used.
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! For more information, you can refer to the basic videos at https://www.youtube.com/playlist?list=PLOk8LhtEwUVn8e3RUfk-rX_RB3f9_ulYg. Thank you for following this post! ?