Jump to content


Photo

Review your object inheritance


  • Please log in to reply
No replies to this topic

#1 Smarty

Smarty

    GMC Member

  • Retired Staff
  • 7213 posts
  • Version:GM:Studio

Posted 08 November 2011 - 04:24 PM

I'm a heavy user of object inheritance. It's tremendously useful for game development and maintenance purposes. Most of my projects, even the small ones, have a pretty intricate object inheritance scheme. It is therefore a shame that GameMaker does not have a proper method to be able to review the inheritance scheme. I really need this to be able to easily see if the inheritance has been properly set to all objects in the game, and to see what parent I need to address to include all the relevant children. I've left some change request for better inheritance support at YYG but it seems to be off the radar until GM9.

I have therefore created a script that creates an overview of your game's inheritance at run time. It lists the inheritance in a simple text file. Parent objects are marked with a +, objects without children with a -. Children are listed below their parents at a certain indentation, into any required level of depth.

How to use
  • Copy / paste the script in your project.
  • Run the game in Windows debug mode (it doesn't work in HTML5).
  • In the debug window, execute the script.
Script name: inheritance_review
var i,n,objects,tree,levels,level,pos,fn,f,parent,lead;// Find maximum object ID to look forn=object_add();object_delete(n);// File to write inheritance tofn='inheritance.txt';objects=ds_list_create();tree=ds_list_create();levels=ds_list_create();// Create list of objectsfor (i=0; i<n; i+=1)    if (object_exists(i)) ds_list_add(objects,i);// Create root list of objectsfor (i=ds_list_size(objects)-1; i>=0; i-=1)   {        n=ds_list_find_value(objects,i);        if (object_get_parent(n)<0)            {                ds_list_add(tree,n);                ds_list_add(levels,0);                ds_list_delete(objects,i);            }   }// And now add to levelswhile (ds_list_size(objects)!=0)   {        for (i=ds_list_size(objects)-1; i>=0; i-=1)            {                n=ds_list_find_value(objects,i);                parent=object_get_parent(n);                // Is the parent on the list?                pos=ds_list_find_index(tree,parent);                if (pos>=0)                    {                        // Yes: get the level of the parent and add one                        level=ds_list_find_value(levels,pos);                        // Add below the parent                        ds_list_insert(tree,pos+1,n);                        ds_list_insert(levels,pos+1,level+1);                        ds_list_delete(objects,i);                    }            }    }  // Create the fileif (file_exists(fn)) file_delete(fn);f=file_text_open_write(fn);file_text_write_string(f,'OBJECT INHERITANCE SCHEME');file_text_writeln(f);// Iterate through the lists and write contentsfor (i=0; i<ds_list_size(tree); i+=1)    {        n=ds_list_find_value(levels,i);        if (n=0) file_text_writeln(f);        if (ds_list_find_value(levels,i+1)>n) lead='+' else lead='-';        repeat (n) file_text_write_string(f,'   ');        file_text_write_string(f,lead+' '+object_get_name(ds_list_find_value(tree,i)));        file_text_writeln(f);    }    // The end    file_text_close(f);ds_list_destroy(objects);ds_list_destroy(tree);ds_list_destroy(levels);execute_shell('notepad.exe',fn);

Edited by Smarty, 08 November 2011 - 04:43 PM.

  • 2




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users