Book Image

Gamemaker Essentials

4 (1)
Book Image

Gamemaker Essentials

4 (1)

Overview of this book

Table of Contents (16 chapters)

Scripts


Scripts in GameMaker are blocks of code not directly related to any object in a project. A script is accessible by all objects in a project at any time and allows developers to create their own functions using GML.

Scripts allow developers to create complex calculations and have the answer returned and stored in a variable as an end result. Scripts are also commonly used when multiple objects are meant to behave the same way. Instead of typing up the same code in every object, a script can be used and run in each object.

Let's take a look at scripts and how they are used.

Creating a script

The first step to using a script is creating one. To do this, click on the icon in the main toolbar that looks a bit like a new page with a play button on it .

This will create a new script and display the code editor so we can start writing code. Before typing anything, we need to know what we want this script to do. Will it be a simple piece of code? Will it need to return a value at the end? How...