Home

Awesome

rt-shell

banner graphic

rt-shell, or run-time shell an easy-to-use, customizable, and extensible cheat/debug console for GameMaker Studio 2.3+.

Table of Contents

Setup

Integrating rt-shell into your project is simple: just download the latest release, and then in GameMaker Studio click on the Tools menu and select Import Local Package. Choose the .yymps file you downloaded, and import all assets.

Alternatively you can install rt-shell from the Game Maker Marketplace.

The obj_shell object is a persistent object, so you only need to include or create it once, though it is smart enough to automatically handle excess instances. The default way to open the shell is Ctrl + Shift + C, and it can be closed by pressing Esc.

Writing Your Own Shell Commands

rt-shell will execute any global scripts whose names start with sh_. You can see the example scripts included with the test project in scr_shell_scripts.gml.

Let's write a simple "Hello World" commands together. We first need a place to create the function, so create a Script asset in your project. The name of this asset isn't important, but we can call it scr_shell_scripts as I have done in the test project.

Now let's write our function! We want it to take an argument as input, and print "Hello [argument]!" to the console. Like so:

A "Hello World" example

Our function needs to start with sh_, so let's call it sh_say_greeting. As you can see in the example screenshot above, you do not include the sh_ when calling the function.

rt-shell functions take an array called args as an argument, and any arguments passed to the function at the console are present in this array in GML. args[0] always contains the name of the function, as in typical shell programming, and args[1] and onwards are the real arguments passed in. Your input string is split into arguments on the space character, and you can use double-quotes to pass in an argument that contains spaces (i.e. say_greeting "Daikon Games")

rt-shell functions can optionally return a string, and if they do that string will be printed to the console.

With all that said, here's our final hello world function:

function sh_say_greeting (args) {
	return "Hello " + args[1] + "!";
}

Simple, right? With that function in place, you can call say_greeting from the shell as you saw in the screenshot above. I'm sure you can think of all sorts of commands that would come in handy for debugging and testing your game. How about a script that set's the player's max health, or money counter? A script that spawns an enemy or a treasure item? Experiment and have fun, happy developing!

Adding Command Metadata

rt-shell provides a way for you to add metadata to your commands. This will let you see possible arguments and autocomplete suggestions within the shell, as well as let you plug into the shell's built-in help commands to document your own functions!

Adding metadata works much the same way as adding your custom commands in the first place. You simply create a new function that begins with meta_ followed by the name of your function. For instance, if you had a function sh_create_balloon then you could add metadata by creating another function meta_create_balloon. The part of the name after sh_ and after meta_ must match exactly for them to be linked.

Let's say that sh_create_balloon looked like this:

function sh_create_balloon (args) {
	var mX = args[1];
	var mY = args[2];
	var balloon = instance_create_layer(mX, mY, "DemoInstances", obj_balloon);
	balloon.mType = args[3];
	balloon.mColor = args[4];
}

You can see that it takes four arguments: X/Y coordinates and two arguments defining a type and color. We can then make an associated metadata function. Every metadata function should return a struct with a specific format, as you can see:

function meta_create_balloon() {
	return {
		description: "create a balloon",
		arguments: ["x", "y", "type", "color"],
		suggestions: [
			mouseArgumentType.worldX,
			mouseArgumentType.worldY,
			["normal", "animal_dog", "animal_snake"],
			function() {
				var _colors = [];
				// some code that fetches a dynamic list of available colors here
				return _colors;
			}
		],
		argumentDescriptions: [
			"the X coordinate to create the balloon at",
			"the Y coordinate to create the balloon at",
			"the type of balloon to create",
			"the color of the balloon"
		],
		hidden: false,
		deferred: false
	}
}

When you go to type your script into the shell your argument hints will show up like so:

argument hints

and so will your autocompletion suggestions:

suggestions

The command will also display the arguments and description fields when running help create_balloon.

Some things to keep in mind:

  1. The function names must match after the sh_ and meta_ prefixes.
  2. The order of the array items in arguments, suggestions, and argumentDescriptions must line up
  3. If suggestions aren't needed for an argument just input a blank array [] or undefined
  4. Each of the items inside suggestions can be either a static array of possible suggestions, or a function that returns an array. If you use a function, it will be called at run-time, making the suggestions dynamic!
  5. description and argumentDescriptions are optional, they're only used for the help output
  6. hidden is optional, but if hidden is set to true, the function will not appear in the help output, or in autocomplete suggestions! This way you can add secret cheat codes. You will still be able to type help hidden_function_name and see help output, but only if you know that hidden function's name in the first place.
  7. deferred is optional, but if deferred is set to true, the function will not execute directly when called. Instead it will be queued up, and all deferred functions in the queue will run in sequence when the shell is closed.

Here is a full reference of the properties that can appear in the struct returned by meta_ functions:

FieldDescription
descriptionThe text that will be printed by help about this script
argumentsAn array containing the names of the arguments to this script, these will appear both in help and as input hints at the console
argumentDescriptionsAn array containing text describing each argument, to be printed by help. The order must match arguments
suggestionsAn array containing suggestions for each argument, that will appear while typing the arguments. The order must match arguments. Each value can be either a static array of possible values for the argument, a function which returns an array of possible values, or an enum value of the mouseArgumentType enum for mouse-cursor based completion (described below)
hiddenDefaults to false if not provided. If true, the script will not appear in the help output, or in autocomplete suggestions! This way you can add secret cheat codes. You will still be able to type help hidden_function_name and see help output, but only if you know that hidden function's name in the first place.
deferredDefaults to false if not provided. If true, the script will not execute directly when called. Instead it will be queued up, and all deferred scripts in the queue will run in sequence when the shell is closed.

You may have noticed the mouseArgumentType enum as a possible value for the items in suggestions. If an argument's corresponding suggestions value is one of the following mouseArgumentType values, then at the console prompt while inputting that argument, a value will be hinted at based on the current position of the mouse cursor. If the left mouse button is pressed while hinting at a value, that value will be accepted and inserted into the console. The following values for that enum are possible:

ValueDescription
mouseArgumentType.worldXThe hint will be the current world-space X coordinate of the mouse cursor
mouseArgumentType.worldYThe hint will be the current world-space Y coordinate of the mouse cursor
mouseArgumentType.guiXThe hint will be the current GUI-space X coordinate of the mouse cursor
mouseArgumentType.guiYThe hint will be the current GUI-space Y coordinate of the mouse cursor
instanceIdThe hint will be the instance ID of the instance below the mouse cursor
objectIdThe hint will be the object ID of the instance below the mouse cursor

By using these mouse argument types appropriately, you can make very user-friendly functions for yourself, like the ability to spawn an object at your mouse cursor by using the worldX and worldY values, as shown in the create_balloon example above, or performing actions on a specific instance by clicking on it. It's a powerful tool!

Keyboard Shortcuts

In the shell, there are a number of useful keyboard shortcuts. These are all triggered using the Meta-key which by default is Control, but can be altered (see Configuring rt-shell)

Key ComboAction
Meta-key + A or HomeMove cursor to the start of the line
Meta-key + E or EndMove cursor to the end of the line
Meta-key + Left ArrowMove cursor left one word (separated by spaces)
Meta-key + Right ArrowMove cursor right one word (separated by spaces)
Meta-key + BackspaceDelete from the cursor backwards to the preceding space
Meta-key + KDelete forward from the cursor to the end of the line, and store the deleted text on a clipboard (this is equivalent to GNU-style "kill", but our clipboard only stores one thing rather than a ring)
Meta-key + YInsert previously "killed" text at the cursor position (this is equivalent to GNU-style "yank", but our clipboard only stores one thing rather than a ring )
Meta-key + CAbort the current command. This will put the aborted command into the output history, but not execute it, and will return your shell to a blank input

Configuring rt-shell

The following variables on the obj_shell object can be configured. They are defined on the object's Variable Definitions panel in the IDE. It is recommended that you instantiate obj_shell programatically and then set these parameters on the created instance via code. This way you can upgrade to a newer version of rt-shell without having to re-configure your shell object!

Appearance Configuration

variabledefinitiondefault
widthThe width, in GUI pixels, of the shell500
heightThe height, in GUI pixels, of the shell96
screenAnchorPointVThe vertical location on the screen to anchor the console to, as a string. Possible values are "top", "middle", or "bottom"."bottom"
screenAnchorPointHThe horizontal location on the screen to anchor the console to, as a string. Possible values are "left", "center", or "right"."center"
anchorMarginThe number of pixels away from the anchor point to draw the shell. In practice, the margin from the top or bottom of the screen, depending on how you have set screenAnchorPoint4
consolePaddingVThe number of pixels of padding to place around the vertical edges of the shell window.4
consolePaddingHThe number of pixels of padding to place around the horizontal edges of the shell window.6
promptA character or string to print as a command prompt$
promptColorThe font color to draw the prompt, as a GML expressionmake_color_rgb(237, 0, 54)
consoleColorThe background color of the console itself, as a GML expressionc_black
consoleAlphaThe opacity of the console itself, 0.0 being fully transparent and 1.0 being fully opaque0.9
consoleFontThe GML font resource to draw all the console text with. The default is included with the package, and uses the Raph Levien's "Inconsolata" fontfont_console
fontColorThe font color to draw all console text with, as a GML expressionmake_color_rgb(255, 242, 245)
fontColorSecondaryThe font color to draw suggestions and history with, as a GML expressionmake_color_rgb(140, 118, 123)
cornerRadiusThe radius in pixels to round the corners of the shell. A value of 0 would result in perfectly squared corners12
scrollBarWidthThe width in pixels of the scrollbar.5
autocompleteBackgroundColorThe background color of the autocompletion box, as a GML expressionc_black
autocompletePaddingThe number of pixels of padding to place around the autocompletion box2
consoleBackgroundA sprite to use as the background of the shell. If set, this will override consoleColor. A 9-slice configured sprite is expected, as it will be drawn stretched to the size of the console.noone
suggestionsBackgroundA sprite to use as the background of the autocompletion box. If set, this will override autocompleteBackgroundColor. A 9-slice configured sprite is expected, as it will be drawn stretched to the size of the autocompletion box.noone

You can see examples of various ways to customize the shell's appearance on the Theme Gallery page!

Other Configuration

variabledefinitiondefault
openKeyThe key that opens the console, in combination with the modifierKeys if any. In the form of an expression.ord("C")
openModifiersA multi-select of special keys for use with openKey. All the selected keys must be pressed in combination with openKey to open the consolevk_control, vk_shift
openFunctionA reference to a function that will be executed every time the shell is opened. Could be used to pause the game when the shell opens, for exampleundefined
closeFunctionA reference to a function that will be executed every time the shell is closed. Could be used to unpause the game when the shell closes, for exampleundefined
enableAutoCompleteWhether or not to use the new autocompletion box. Marking this false will only provide in-line completion suggestions.true
cycleSuggestionsKeyThe key for cycling through suggestions for autocompletion. In the form of an expression.vk_tab
cycleSuggestionsModifiersA multi-select of special keys for use with cycleSuggestionsKey. All the selected keys must be pressed in combination with cycleSuggestionsKey to cycle the suggestions.None
cycleSuggestionsReverseKeyThe key for cycling through suggestions for autocompletion in reverse order. In the form of an expression.vk_tab
cycleSuggestionsReverseModifiersA multi-select of special keys for use with cycleSuggestionsReverseKey. All the selected keys must be pressed in combination with cycleSuggestionsReverseKey to cycle the suggestions in reverse.vk_shift
historyUpKeyThe key for cycling up through the command history. In the form of an expression.vk_up
historyUpModifiersA multi-select of special keys for use with historyUpKey. All the selected keys must be pressed in combination with historyUpKey to cycle the history up.None
historyDownKeyThe key for cycling down through the command history. In the form of an expression.vk_down
historyDownModifiersA multi-select of special keys for use with historyUpKey. All the selected keys must be pressed in combination with historyUpKey to cycle the history down.None
metaKeyUsed to perform keyboard shortcutsvk_control
keyRepeatInitialDelayThe amount of time in frames to wait after pressing and holding a key before it begins to repeat.25
keyRepeatDelayThe amount of time in frames to wait between each repeat of a held key.4
scrollSpeedThe number of pixels at a time to scroll the console when moving the mouse wheel.16
scrollSmoothnessHow smooth you want the scrolling to be when moving the mouse wheel. A number between 0 - 1.0.5
saveHistoryIf true, the console's command history and output (up to savedHistoryMaxSize entries) will be saved to a file on disk every time the shell is closed, and re-loaded when the shell is first created. This will let you keep a history between play sessions.false
savedHistoryMaxSizeThe maximum number of history entries and console output rows to save to disk, if saveHistory is true.100

Licensing

rt-shell is licensed under Creative Commons BY 4.0. Essentially, you may use it, change it, ship it, and share it, with attribution. Just make sure to somewhere mention the use of rt-shell by Daikon Games!

Attribution

Fonts

Default shell font, Consolas © 2018 Microsoft Corporation. All rights reserved. Demo font, Peaberry by emhuo