Home

Awesome

INSPECTRON 1.0.1

A library for easily creating GameMaker debug views

What is Inspectron?

Inspectron is a library designed to help you easily create debug views for objects in your game, and lets you easily customize what values get displayed using a simple fluent API. Inspectron calculates the best place to put the debug view, ensuring that it's sized appropriately and remains entirely on screen, and automatically closes the view if the target object is destroyed.

Here's an example of Inspectron working out-of-the-box in the Windy Woods template project: image

Inspectron can automatically generate a debug view for built-in variables on an instance, as you can see above, but it also allows you to easily customize what values get displayed for objects you create.

Here's an example of the custom inspection for my GameMaker UI library, YUI: image

Quick Start

First, import the .yymps package from the Releases page into your project. Once that's done, you have a few options for how to enable Inspectron in your project, but the fastest way to see what Inspectron can do is to enable the default mouse gesture, which is as easy as setting one config macro.

To start, open the InspectronConfig script asset in the project root and set INSPECTRON_GESTURE_ENABLED to true:

// whether to automatically call InspectronSetGesture with the gesture settings below
#macro INSPECTRON_GESTURE_ENABLED true

Once this is set, Inspectron will configure the default mouse gesture, Shift+Middle-Click, to open the Inspectron debug view for any instance under the mouse cursor. If INSPECTRON_AUTO_INSPECT_ENABLED is true (which it is by default), Inspectron will automatically display many of the common built-in variables for those instances (and allow you to edit some of them!). You can see what this looks like in that first Windy Woods screenshot above.

You can customize which button and which modifier key to use in the config macros below that line:

// mouse button and optional modifier key to trigger Inspectron if enabled above
#macro INSPECTRON_GESTURE_MOUSE_BUTTON mb_middle
#macro INSPECTRON_GESTURE_MODIFIER vk_shift // set to undefined for no modifier

Customize Which Objects Get Inspected

The automatic gesture method will show the Inspectron view for all instances under the mouse cursor, but if your game is complex you may want to customize which objects actually get included in the view, especially if you want to differentiate between instances that draw in the game world vs instances that draw to the GUI layer.

To do that, you'll need an object event to trigger Inspectron, where you can customize what Inspectron does. For example, you can add a Global Middle Released event to a controller object in your game. Once you have that, you'll want to call InspectronGo() with some custom arguments. For example:

// in Global Middle Released event
InspectronGo(obj_character_base, obj_gui_base, "Characters and GUI");

Customize the Inspectron View for Different Objects

The built-in variables that Inspectron can display automatically are convenient, but you'll likely want to make your custom variables on objects inspectable as well. Inspectron makes this very easy, by providing a fluent API to tell Inspectron what variables to display and how to display them. Inspectron will then take care of making the underlying dbg_ function calls for you to display the Debug view.

You should define the Inspectron fields for an object at the very end of the Create event of your object. For example:

// in obj_player Create Event

...
// All the other code in your create event
...

Inspectron()
  .Section("player")
  .Watch(nameof(player_health), "Health")
  .Checkbox(nameof(invulnerable))
  .BuiltIn()

The above code will tell Inspectron to show:

The fluent API means you can keep calling Inspectron field functions in sequence until you've defined everything you want to display.

NOTE: the first parameter must be the name of the variable on the instance that you want to display, as a string. It's best practice to use the nameof() function provided by GML, as if you later rename that variable where it's defined, the nameof() function will report an error.

Handling Object Parents (and Inherited Constructors)

Actually you don't really have to do anything special here. If you define an Inspectron on a parent object, and then call Inspectron.Etc() on a child object, Inspectron will automatically include the parent inspectron in the child object's definition, at the end. This works no matter how many object parent/child relationships you set up.

You may want to include a .Section or .Header in child objects to make clear about which variables belong to which object. The same is true for constructor functions that inherit another constructor.

Supported Functions

Basic

Pickers (dropdowns)

Advanced

Others (experimental)

Some other functions may be defined in the Inspectron script file but should be considered experimental (and hence unsupported) if not listed above.