Why: You tried to use a variable in the Step Event before it was created in the Create Event.
Fix: Initialize everything in the Create Event, even if it's just to undefined or 0.
If you override an event in a child object, the parent's code won't run unless you call this.
You can also use the Collision event (e.g., Collision with obj_lava):
hp -= 10;
x = checkpoint_x;
y = checkpoint_y;
// Step Event var key_left = keyboard_check(vk_left); var key_right = keyboard_check(vk_right); var key_jump = keyboard_check_pressed(vk_space); // true only for one frame
// Custom keys (ASCII) var key_attack = keyboard_check(ord('X'));
Use this for HUD (health, ammo, score).
// Draw GUI Event
draw_set_color(c_black);
draw_text(10, 10, "Score: " + string(global.score));
draw_text(10, 30, "Lives: " + string(global.lives));
// Modern Map using Struct
var inventory =
gold: 150,
weapons: ["Dagger", "Bow"]
;
inventory.gold += 50; // Easy access
Structs are GML’s version of JSON-like objects. They are lightweight and perfect for save files or stat containers.
// Create a struct var player_stats = level: 5, hp: 100, attack: function(enemy) enemy.hp -= 10; ;
// Call the function inside the struct player_stats.attack(some_enemy);