Coding in GML
Coding in GML
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!");
}
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;
}
gml
Copiar código
// In the create event of an object
health = 100;
Here's an example of a simple game where a player controls a character that moves
around the screen.
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;
}
If you have specific questions or need help with a particular aspect of GML, feel free to
ask!