• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML organizational tricks

D

Darth Binary 1010

Guest
after doing a game jam and completing my first gm2 game, i've realized that i have to relearn how to organize my code in this engine after coming from using javascript frameworks. what are some organizational tricks that you learned down the road that someone new to GM2 might not find out for a while?
 
M

MarceloP

Guest
- Delta Time
- Layer System
- Depth with Layers System, based on Y
- Surfaces and its applications with Blend Modes
- Shaders
- Controller/Joysticks
- Mask based collisions
- Tileset based collisions

Those are only some of the many you'll find xD
 
B

boob

Guest
A couple of things:

Code folding
is useful if you don't overuse it, as you can use #region and #endregion to hide very lengthy bits of code when you don't need them, and can just comment what the section does.

Finite state machines almost always have a place somewhere in your game, especially with the types of games that are popular with the GameMaker community. They're probably the single most useful code organization concept I've discovered since my early days. I used to spam nested if statements with tons of variables that held conditions. Turns out, it was processing the same logic as a finite state machine, but with half of the efficiency and 1% the elegance.

Use enumerators if you find yourself using multiple if/else statements or a switch statement with a single variable, and you're comparing strings as placeholders, just use an enumerator. They're more efficient, easier to read, global, and they pop up in code completion, so you always have the list of them at your fingertips.

Imagine you have an inventory system, where each position of the inventory has a few properties, such as: item, color, effect, damage, durability, count, etc.
You could set up an enum as such:
Code:
enum inv
{
   item,
   color,
   effect,
   damage,
   durability,
   count
}
Ternary statements can sometimes be much simpler than a bunch of if/else statements, so use them when you can, but only when they make sense. I tend to overuse them, but I feel that it makes my code more concise. For example:
Code:
if ( mouse_over )
{
   image_blend = c_gray;
}
else
{
   image_blend = c_white;
}
versus:

Code:
image_blend = ( mouse_over ) ? c_gray : c_white;
Some people will disagree with me on this, but use macros. You can create a script called "macros" and define all of your macros with the #macro tag. I use them as a list of constants, and tend to find them useful as arguments for specific parameters in scripts. For example, I have a clk function that simply counts down to zero and then resets to the start number when it's done, but you can also input the macro "CLK_NO_RESET" as the reset parameter. If the script recognizes that as the argument, then it simply doesn't reset the clock.
 

FrostyCat

Redemption Seeker
- Delta Time
- Layer System
- Depth with Layers System, based on Y
- Surfaces and its applications with Blend Modes
- Shaders
- Controller/Joysticks
- Mask based collisions
- Tileset based collisions
These are all task-specific competencies, not one is an organizational pattern.

The original poster is not one of those morons who type "how to make XYZ game" or "how to do XYZ" into YouTube and expect to have a copy-and-paste answer. He wants to know how to structure his code better and be more productive with the tools he has. Here are some examples:
  • Behaviour modelling (e.g. finite state machines, behaviour trees, dependency injections, etc.)
  • Best practices for collaborative work with other programmers and non-technical staff (e.g. adoption of source control, storage and management of non-code assets, on-boarding of non-technical staff, conflict resolution, etc.)
  • Conventions for commenting, readability and future maintainability (e.g. comment-driven coding, line/block length limits, naming schemes, etc.)
  • Design patterns that discourage tight coupling and hard-coding by nature (e.g. use of macros and enumerations, parameterization, user events as callbacks, etc.)
Unlike others languages where discussions on organizational patterns are central to the learning process, such discussions are sorely lacking in GM user circles. No wonder GML has issues with rookies who can "create" platformers and role-playing games, yet can't even scope a variable right.
 
Last edited:
M

MarceloP

Guest
These are all task-specific competencies, not one is an organizational pattern.

The original poster is not one of those morons who type "how to make XYZ game" or "how to do XYZ" into YouTube and expect to have a copy-and-paste answer. He wants to know how to structure his code better and be more productive with the tools he has. Here are some examples:
  • Behaviour modelling (e.g. finite state machines, behaviour trees, dependency injections, etc.)
  • Best practices for collaborative work with other programmers and non-technical staff (e.g. adoption of source control, storage and management of non-art assets, on-boarding of non-technical staff, conflict resolution, etc.)
  • Conventions for commenting, readability and future maintainability (e.g. comment-driven coding, line/block length limits, naming schemes, etc.)
  • Design patterns that discourage tight coupling and hard-coding by nature (e.g. use of macros and enumerations, parameterization, user events as callbacks, etc.)
Unlike others languages where discussions on organizational patterns are central to the learning process, such discussions are sorely lacking in GM user circles. No wonder GML has issues with rookies who can "create" platformers and role-playing games, yet can't even scope a variable right.
Sorry for mis-answering your topic =(
I think people may have already answered mostly what you wanted, so I think they're not only right, but guiding you in the right path :)
 

samspade

Member
He wants to know how to structure his code better and be more productive with the tools he has. Here are some examples:
  • Behaviour modelling (e.g. finite state machines, behaviour trees, dependency injections, etc.)
  • Best practices for collaborative work with other programmers and non-technical staff (e.g. adoption of source control, storage and management of non-code assets, on-boarding of non-technical staff, conflict resolution, etc.)
  • Conventions for commenting, readability and future maintainability (e.g. comment-driven coding, line/block length limits, naming schemes, etc.)
  • Design patterns that discourage tight coupling and hard-coding by nature (e.g. use of macros and enumerations, parameterization, user events as callbacks, etc.)
Unlike others languages where discussions on organizational patterns are central to the learning process, such discussions are sorely lacking in GM user circles. No wonder GML has issues with rookies who can "create" platformers and role-playing games, yet can't even scope a variable right.
Would you have some suggestions where we could learn these?
 

JackTurbo

Member
Game programming patterns by Rob Nystrom is a great way to learn established patterns for game code organisation.

http://gameprogrammingpatterns.com

Not at all gml focused but a lot if it is transferable if you put your mind to it


Also a personal favourite organisational tool is script_execute. It is a super versatile function that allows you to run scripts stored in variables and can even be used via a "with" statement. This paired with object parenting can allow for some neat approaches to building flexible systems.
 
Last edited:
Top