Gamemaker Studio 2 Gml | TRUSTED | How-To |
// Set the x coordinate of the player object to 100 obj_player.x = 100; This is GML’s superpower. with allows you to switch the scope to another object temporarily .
// If statement if (keyboard_check(vk_space) && jumps > 0) { vspeed = -10; jumps--; } // Switch statement (Great for state machines) switch (state) { case "idle": sprite_index = spr_idle; break; case "run": sprite_index = spr_run; break; } gamemaker studio 2 gml
Never use obj_enemy.x to get a single value if there are multiple enemies (which one?). Use with or instance_nearest() instead. Part 4: Data Structures & Arrays (Post 2.3 Update) The 2.3 update modernized GML significantly. Gone are the clunky legacy functions ( ds_list_add ). We now have real arrays and structs. Arrays Arrays can be mixed-type and nested. // Set the x coordinate of the player
// Accessing value = map[1][2]; // Returns 1 Structs are GML’s version of JSON-like objects. They are lightweight and perfect for save files or stat containers. Use with or instance_nearest() instead
// 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); You can now write true Object-Oriented GML.