Modularized code, although easy to use and efficient, isn't always the easiest thing to implement. Here are some tips to help you modularize your code: Scripts Use scripts to their fullest potential. Scripts without arguments are fine, but they lack the flexibility that would otherwise turn the script into a function. Say you have a room in your game that has a obj_blocks for making walls, floors, and ceilings. Now lets say that you want to put grass on top of all of the the blocks that don't have blocks on top of them. Coding the grass by itself inside of the obj_block's events would be fine, but what if you made a script that any object could use to put grass atop it's self. Say you have tombs and ruins that could use a couple flowers and vines growing around them. With a script, you make one piece of code with a couple arguments and your off. Here's what using a function like this would look like: with(obj_block) { scr_shrubberize(1,1,0) } The
arguments for the above script are all true/false (Grass, Flowers,
Vines), so in this case, the script scr_shrubberize would put grass
and flowers on the tops of all of the obj_blocks in the level. Once
your done putting shrubberies on top of the obj_blocks, you can go
ahead and easily modify the code for all of the obj_statues and
obj_tombs. That, and you shall be allowed to pass through the forest of the Knights Who Say NI ! Parents Use parents when you have a bunch of objects that have the same code in their events. If your parent has only one event, think about ditching the parent and making a script instead. (Disclaimer to the GM illiterate: Don't run away from home to go start making movies, parents in Game Maker are only cookie cutters for objects that are almost identical to their parent objects.) Also, refrain from using parents if there are only a couple child objects. This just makes the game more complicated than it needs to be. Use external files External files can be used to make multiple objects that have different variable values. For example; let's say you have magic swords in your game, all with a different name, description, history, and attributes. Instead of making twenty obj_sword1-20's that populate the entire object folder in Game Maker, make text files for all of the different swords and code a script that reads from those text files to create the swords. You can now add any sword you want just by writing an ordinary text file. Keep modularization in mind If you program in Game Maker with modularization in mind, your code will eventually look and function like modularized code. And you know what they say about code that looks and functions like modularized code right? IT IS! |
