0% found this document useful (0 votes)
16 views3 pages

Coding in GML

CODING IN GML COLL ISN'T IT?

Uploaded by

Gustavo Tondin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Coding in GML

CODING IN GML COLL ISN'T IT?

Uploaded by

Gustavo Tondin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CODING IN GML

GML (GameMaker Language) is a programming language used in GameMaker Studio,


a popular game development platform. GML is designed to be easy to learn for
beginners while providing powerful features for more advanced users. Here's a brief
introduction to GML coding:

Basics of GML

1. Variables:
o Variables are used to store data values.

gml
Copiar código
var score;
score = 10;

2. Data Types:
o GML supports several data types, including integers, floats, strings,
arrays, and structs.

gml
Copiar código
var playerName = "Alex";
var health = 100;
var position = [x, y];

3. Control Structures:
o GML uses common control structures like if statements, loops, and
switches.

gml
Copiar código
if (score > 50) {
show_message("You win!");
}

for (var i = 0; i < 10; i++) {


// Loop code
}

switch (weapon) {
case "sword":
// Sword code
break;
case "bow":
// Bow code
break;
}

4. Functions:
o Functions in GML are used to perform specific tasks. GameMaker
provides many built-in functions, and you can also define your own.

gml
Copiar código
function add(a, b) {
return a + b;
}

var result = add(5, 3); // result is 8

5. Objects and Events:


o GameMaker Studio uses objects to represent elements in the game.
Objects have events (such as create, step, and draw) that define their
behavior.

gml
Copiar código
// In the create event of an object
health = 100;

// In the step event of an object


x += 1; // Move the object to the right every frame

// In the draw event of an object


draw_self(); // Draw the object
draw_text(x, y - 20, string(health)); // Draw health above the
object

Creating a Simple Game

Here's an example of a simple game where a player controls a character that moves
around the screen.

1. Creating the Player Object:


o Create a new object called obj_player.
2. Adding a Sprite:
o Assign a sprite to obj_player for visual representation.
3. Implementing Movement:
o Add code to the Step event of obj_player to handle movement.

gml
Copiar código
// In the Step event of obj_player
if (keyboard_check(vk_left)) {
x -= 4;
}
if (keyboard_check(vk_right)) {
x += 4;
}
if (keyboard_check(vk_up)) {
y -= 4;
}
if (keyboard_check(vk_down)) {
y += 4;
}

4. Creating the Game Room:


o Create a new room and place the obj_player in it.
5. Running the Game:
o Run the game to see the player object moving around the screen based on
keyboard input.

Resources and Learning

 Documentation: The official GameMaker Studio documentation is an excellent


resource for learning GML.
 Tutorials: Many tutorials are available online, both on the YoYo Games
website and on platforms like YouTube.
 Community: Engaging with the GameMaker community through forums and
social media can be helpful for getting tips and support.

If you have specific questions or need help with a particular aspect of GML, feel free to
ask!

You might also like