SCRIPTING
SCRIPTING
Scripting is a powerful tool that allows us to create gameplay behaviors and logic for our game.
Scripting is a powerful tool that allows us to create gameplay behaviors and logic for our game.
It is done by creating a Script in the FileSystem, which is essentially a text document filled with code that
It is done by creating a Script in the FileSystem, which is essentially a text document filled with code that
we can then attach to a node, via the Script property, which every node has. Our code will then
we can then attach to a node, via the Script property, which every node has. Our code will then
affect the node directly, doing things like influencing the player’s position or acting as an enemy AI.
affect the node directly, doing things like influencing the player’s position or acting as an enemy AI.
Create a New Scene
Create a New Scene
Add a Node2D
Add a Node2D
In the Inspector go to the Script Property
In the Inspector go to the Script Property
Choose New Script from the drop down.
Choose New Script from the drop down.
Save your Script as IntroToScripting
Save your Script as IntroToScripting
Script Editor
Script Editor
The Script Editor
The Script Editor
The Script Editor is where we can write down our code.
The Script Editor is where we can write down our code.
It is a text editor specifically designed for GDScript, which is the scripting language of Godot.
It is a text editor specifically designed for GDScript, which is the scripting language of Godot.
By default there is some code already in the document, which is standard when creating a new script in Godot.
By default there is some code already in the document, which is standard when creating a new script in Godot.
On the left of the editor, you will find two lists, one for the Scripts in the project, and another for the
On the left of the editor, you will find two lists, one for the Scripts in the project, and another for the
Methods in the current script, which we will investigate further in another section.
Methods in the current script, which we will investigate further in another section.
Save your Scene.
Save your Scene.