Your first script

By: Nathan Lovato - March 31, 2021

In this lesson, you will get to create your first script with Godot’s GDScript programming language.

You will first create a character turning in circles. Then, we’ll see how to listen to the players' input and make it controllable with the keyboard’s arrow keys.

Below, I added some extra details on top of what we covered in the video.

If you’re interested, I made a lesson that explains variables, functions, loops, and other basic programming features of GDScript: Intro to programming with GDScript.

It’s more presentation-style, going through each keyword and concept one at a time.

What’s the difference between a property and a variable?

In the video, I tell you that variables outside functions are properties.

This is one of the terms we use to designate variables attached to an entire object (an extended Sprite in this case).

They’re also commonly called member variables, attributes, or fields.

Their role is to hold an object’s data like our Godot head’s speed and angular_speed.

Unlike local variables, which are just labels we used to name values inside a function, properties are bound to an object.

In this lesson, the speed variable represents the speed of our Godot sprite. And not any copy of it: only the one that’s in our running scene.

Note that the term property, like method, has to do with the object-oriented programming paradigm, which Godot relies on, like many other game engines.

What’s object-oriented programming?

In short, it’s a whole approach to programming taking its root in the 1960s.

In object-oriented programming, you break down a program into objects, small parts that strive to be as self-contained as possible, helping you keep things manageable even in big projects.

You can think of objects as little machines that bundle both behavior and data.

Behavior comes in the form of functions you can call, like Vector2.rotated(). In this context, we tend to say method instead of function.

Data comes in the form of variables we call properties, representing the machine’s current state, like the position and rotation properties.

You mentioned something called a method?

In object-oriented programming, we call “method” a function attached to an object.

Like properties, we use the term to differentiate them from functions that are not attached to an object, although that’s something you won’t see often in Godot and GDScript.

Anyway, like a property is a variable, a method is a function. They’re just particular kinds of them.

Why all those confusing terms?

All these new words can feel like unnecessary jargon.

Objects, properties, methods, classes; it’s all part of the terminology that programmers use to talk and reason about programs.

Like most specific terminology, it’s beneficial on the job, to communicate precisely with fellow developers. You’ll get stuck a lot in code, and to explain your problem and get good support, you’ll need to use some of these words.

While learning, you don’t need to learn many. Also, you don’t need to think too much about it: you’ll memorize them through practice.

Still, you should get familiar with the terms above because you will encounter them often in tutorials and programming books.

Coming next

Okay, so that’s enough for a first experience scripting in Godot.

In the next lesson, we will play with signals.

And after that, you will get to create a complete 2D game from scratch, followed by a 3D one.

See you there!

Made by

Nathan Lovato

GDQuest founder. Courteous designer with a taste for Free Software. I promote sharing and collaboration.

No questions yet

Got a question or feedback regarding this guide?
Please use the form below.

Enter your email to get notified when someone replies to your comment.
We encrypt your addres with a strong 256-bit AES encryption.
We'll only use your address for notifications. You can unsubscribe anytime.