Scripts at a high level are units of logic you can attach to Game Objects. They allow you to implement functionality within your game. The language scripts are written is known as GDScript.
Now, there are some interesting points to remember about scripts — some secrets. As you get further into scripting you find out that they are classes!
Scripts Are Classes
Similar to a programming language like Java, a script is considered a class and extends some other class in most cases. A class at a high level means that a script shares its functionality with its parent. There are good examples of this that will come up in your projects such as enemies and players.
A player needs to have hit points, the ability to take damage, and the ability to move. An enemy needs similar functionality. Therefore it would make sense for both the enemy and player to have the same script that extends KinematicBody2D. Why? Because the KinematicBody2D class has functions and properties that let you easily implement movement and still write functionality for handling hp. Here’s an example script to do just that.
As you can see, we have implemented both movement and handling health points in a single script. With a few modifications, we can use this on enemies to implement the same behavior. Note the extend keyword; that means any object in our game that uses this script must be of the KinematicBody2D type.
Now, there are a lot more interesting things about scripts, which we’ll get into in future posts. Stay tuned for now and good luck making your game!