GML and Data = OOP
- The Boss
- Jan 14
- 3 min read
Updated: Jan 15

The temptation when working with a platform like GameMaker is to get loads of flashy stuff running on the screen. I have done that to experiment and prototype, but that seems like a bottom up approach and I've found in my day to day work that doesn't pay off for a project. I code network automation tools for a living. Most engineers who switch to coding start thinking about what they would type into a router and work up. I'm not sure if it is due to the fact I have a formal education in software engineering or I'm one of those rare engineers that is strategic. In a former role they psych profiled us and I was the only one out of 30 engineers that flagged as being strategic. Regardless I've taken a different appoach, top down. The key to success I've found in my working life is to start with the data. Code logic just writes itself if you do that. But this means taking a step back and thinking about what you're trying to achieve and abstract all the detail from a project and create a data structure around it. Once you have the structure it is just a case of processing that data which I think is a more strategic top down approach. So the question is does this work in a game coding scenario. Well it seems to be, before I have cool stuff running around on the screen I've created code that procedurally generates sections of my game in data strcutures that can be read and used to create objects in the game. It also creates the basis of a save game function. I fixed the last bug tonight and I have generated 4412 elements in just one game area. Well to be exact, because it is procedural that is merely one interation the next will be different. I have thousands of lines of json data but barely hundred lines of code. The beauty is that if I want to change the drop rate of a resource or the chance of an object type appearing or add an entirely new object or area I don't have to touch the code. All I have to do is create a new template. It means I can easily add DLC or a huge amount of variety to keep the game interesting. I could even give users mod access. Not having to touch the code logic which carries the risk of introducing bugs is a huge advantage. Changing code if you're doing things properly also means going through an entire test suite for the smallest changes which is more arduous than testing a new template. But to answer the strap line. GML isn't technically OOP but if you're dealing in json data templates and the GML equivalent structs. All you're doing is creating functions to operate on objects. A collection of functions that operate on a speciffic object could be considered methods and if collected in a folder you have a class. So yes you can have some advantages of OOP with a functional language. Obviously GML doesn't enforce the 5 tenants of OOP so the coder has to be disciplined but if you want any chance of completing a decent sized project you need to be disciplined or the code will be junk anyway. So this is my first project landmark, procedural data creation complete. Next sprint on the jira board is create the game objects in the game itself by reading the procedural data.
Comments