function move_towards(target_x, target_y, speed)
var dx = target_x - x;
var dy = target_y - y;
var dist = point_distance(x, y, target_x, target_y);
if (dist > 0)
x += dx / dist * speed;
y += dy / dist * speed;
Quick Effect:
effect_create_above(ef_explosion, x, y, 1, c_red);
Camera Shake (Custom):
// Create event shake_magnitude = 0;// Step event if (shake_magnitude > 0) camera_set_view_pos(view_camera[0], random(shake_magnitude) - shake_magnitude/2, random(shake_magnitude) - shake_magnitude/2); shake_magnitude -= 0.2; else camera_set_view_pos(view_camera[0], 0, 0);
// Call this when you hit something shake_magnitude = 10;
This is incredibly useful for arrays.
var list = [5, 2, 8, 1]; array_sort(list); // [1, 2, 5, 8] array_reverse(list); // [8, 5, 2, 1]
// Modern filtering var high_scores = array_filter(list, function(score, index) return score > 3; ); // Returns [8, 5]
Arrays can be mixed-type and nested.
// 1D Array inventory = ["sword", "shield", "potion"];// 2D Array (Grid) map = [ [1, 1, 0], [1, 0, 1], [0, 0, 1] ];
// Accessing value = map[1][2]; // Returns 1
// Array inventory = ["sword", "shield", "potion"];
// Struct (like a dictionary/object) player_data = name: "Kaelen", level: 5, stats: str: 12, agi: 8 ;
GameMaker Studio 2 GML strikes a perfect balance: It is easy enough for a 12-year-old to make their first "avoid the falling objects" game, yet powerful enough for a solo developer to build a commercial RPG or multiplayer shooter.
By moving from Drag and Drop to GML, you are not just learning a scripting language; you are learning how to think like a programmer. Objects, events, loops, and structs are universal concepts. Mastering GML gives you a transferable skill set while allowing you to focus on what matters most: making the game fun.
So, open GameMaker, create a new Object, open the Create Event, and type: gamemaker studio 2 gml
show_debug_message("Hello, World!");
Your journey into GML starts now.
Do you have a specific GML problem? Remember: if (problem == unsolved) search_manual();
GameMaker Language (GML) is the primary scripting language used in GameMaker Studio 2, designed to provide developers with more control and flexibility than the standard "GML Visual" (formerly Drag and Drop) system. It is an imperative, dynamically typed language often compared to JavaScript and C-family languages. Core GML Concepts Object-Oriented Structure : While primarily procedural, GML uses as templates and as specific entities in the game world. Variable Scopes : Variables can be (temporary within a script), (unique to one object), or (accessible across all rooms and objects). Event-Driven Logic : Code is executed within specific events, such as: Create Event : Runs once when an instance is first spawned. Step Event
: Runs every single frame of the game (typically 60 times per second) for continuous logic like movement. Draw Event
: Specifically for rendering graphics, including sprites and GUI elements. GameMaker Manual Key Features and Syntax Flexible Functions : You can define custom logic using the
keyword, allowing for reusable code across different objects. Simplified Math and Movement : Built-in variables like make 2D movement and collision detection highly accessible. Data Structures : GML supports advanced structures like lists ( ), and grids for complex data management. Visual-to-Code Conversion
: Beginners can start with GML Visual and use a one-way conversion tool to see the equivalent GML code, helping them "graduate" to manual scripting. GameMaker Manual
To create a good post about GameMaker Studio 2 (GMS2) and GML, focus on sharing actionable tips, highlighting useful features like Structs, or providing simple code snippets that solve common problems. Option 1: The "Pro-Tip" Post (Educational) Camera Shake (Custom): // Create event shake_magnitude =
This style works well on platforms like X (Twitter) or LinkedIn to establish yourself as a knowledgeable developer.
Caption: 🚀 Quick #GML Tip: Stop using Alarms for everything! Switch to Time Sources in GameMaker Studio 2 for more control over your game’s logic without the clutter of nested events. 🕒 Key Points to Include:
Logic over Syntax: Remind beginners that learning the logic is the hard part; GML’s syntax is quite friendly, similar to JavaScript.
Clean Code: Advise naming variables logically (e.g., max_player_health instead of mph) to save time during debugging.
Efficiency: Use #macro for constants, but always wrap expressions in brackets to avoid order-of-operation bugs. Option 2: The "Dev Log" Post (Community Engagement)
Best for Reddit or Instagram to show off your current project and get feedback.
In GameMaker Studio 2 (GML), there is no built-in function called "draw_paper" or "create_paper." To achieve a "Deep Paper" effect—where the paper looks like a tangible 3D object with thickness rather than a flat 2D sprite—you need to construct it manually using the 3D drawing functions or a clever combination of 2D primitives.
Below is a robust, commented script that generates a "Deep Paper" effect. It draws the top surface (your texture), the bottom surface (a shadow/under-side), and the side edges (the thickness). (unique to one object)
GameMaker is currently transitioning to GameMaker (LTS vs Beta) . The latest betas introduce Rollback Netcode (for fighting games) and improved GX.games export. Keep your GML updated with the latest runtime.
Memorize these. They are the bread and butter of GMS2.