4

Bringing Structure with Methods and Classes

In Chapter 3, we learned about collection types and loops. These powerful concepts helped us to structure our data and run code an arbitrary number of times.

Being able to reuse code in a loop is great, but what if we want to reuse this code at any arbitrary moment in time? And what if we want to reuse whole structures of code and data, such as – for example – enemies or vehicles?

Methods and classes are exactly the concepts that will help us achieve this level of reuse!

Over the course of this chapter, we’ll see the last few basic concepts of programming. By the end, we will have learned everything that is needed to call ourselves real programmers.

In this chapter, we cover the following main topics: ...

Get Learning GDScript by Developing a Game with Godot 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.