

Next, we check to see if the object has already been described, since multiple instances of the same object can call this function and we only need it to happen once, so we return false. The first few lines are making a variable for the argument passed in, getting a reference to the manager, and checking if the function is being used correctly and there isn’t another object being described. Set an empty 2D in the object's map slot If (ds_map_exists(manager._objTypeMap, object)) If the object already has a definition, skip it. Show_debug_message("Warning: OI_DefineBegin was called, but a previous call wasn't closed using OI_DefineEnd.") Show warning for misuse of the function This is what it all looks like: // OI_DefineBegin Our goal with this function is to set all the initial values to our variables and to set the currObject variable to the one that called the function. Let’s write these three functions now, starting with OI_DefineBegin. You then add all the variables you want to keep track of, and you end it. You call a function to start the description (which returns false if the object has already been described, skipping the rest of the function calls). Here, I decided this is what I was going for: // Create event of the object you want to describe
#GAME MAKER STUDIO PRO ARRAYS CODE#
When I’m working on new features like this one, I usually start by writing how I want the interface to look like, and then I code the actual functions. Last, we have the map where we will store the description about our objects, and two variables to keep track of which object we are describing and the variable index we are on. It is also useful to create a global variable and pass it the id of this object so we can access it easily, but it’s not necessary as you can use instance_find to get the first instance which should be the only one. Since this is part one of the article, I will cover the basic ones, and we will address data structures in the next post because it requires a bit more work. We then create an enumerator with all the data types we will be storing for now. It’s a simple script that looks like this: // Singleton Script _currIndex = 0 // Keeps track of the variable index for the current objectīreaking the code down, we first see we have a script called Singleton that ensures there’s only one copy of this object in the game. _currObject = noone // Keeps track of the object we are defining _objTypeMap = ds_map_create() // Map of 2D arrays to store objects and variable definitions Create a global variable to easily access the manager Enum that lists all valid data types (more can be added if needed) Ensures there's only one instance of this manager Next, write this code in the create event: // oOI_Manager Create event Activate the persistent flag on the object since we need it to be active all the time. That last paragraph may have been a tad confusing, so let’s get started with the code and it should make more sense.įirst, we’ll make an object that will hold the information about every object. It is also possible to do this recursively, so you can inspect the variables of an object if you have a reference to it inside of another one. We can then use this information to create a generic function that achieves our purpose trivially since we can reuse the same functions for every object.

My solution is to have scripts for every data basic data type, alongside a database of objects with their variables and types. The problem is that this solution isn’t scalable, and would get harder to maintain as the project grows. Inspect and modify all the values from an object using a custom editorĪ decent approach to all these problems would be to write a script or user event for every object you want to serialize/inspect and call that.

Debug draw information about an object to the GUI
