The Script Editor

The Script EditorThis section deals with the script editor (also called the text editor) which is where you type in all the code that your game will require to run. This editor is used for creating custom script assets, as well as for coding object events, for adding room creation code, and for many other things, and as such, this section simply details how the script editor works, and not how to create script assets nor how to use Drag and Drop™ to make scripts. For that please see the following sections: 

The script editor is where you write your GameMaker Language code, which is the built-in programming language that GameMaker Studio 2 uses (see the GML Reference section for more details). Once you become more familiar with GameMaker Studio 2 and want to use it to its fullest extent, it is advisable to start learning to use this language, as it greatly expands your possibilities when creating games.

A script asset can be named by right-clicking RMB Icon on it in the Asset Browser and selecting Rename, but note that the script name must conform to the scripting rules for functions, so they can only be alpha-numeric, must start with a letter, and the only symbol they can contain is the "_" under-bar symbol. The script editor in other places cannot be renamed and will have a name specific to what is being edited, like an object event for example.

When you open the script editor window it will have the following options and layout:

Script / Event TabScript / Event Tab

The script editor opens in a window with tabs across the top to let you have multiple scripts or events in one window (although this behaviour can be changed from the Preferences to give a new window to each script or event). You can click LMB Icon on a tab and then drag it to change the tab order, or - if you prefer - you can pull it out of the current window and place it on the workspace to create a new window for that script (or add it to a different window), and you can also maximise the script editor to create a new workspace too. If you drag a script tab out of the IDE window, then a new IDE will be spawned to hold this script resource, and it can be used as you would the Main window.

Note that if you are editing code from an object event in the script editor and you have maximised the script editor or have it on a separate window or workspace, then the right-click RMB Icon editor menu will have some extra options:

Script Editor RMB Object Menu

For information on the rest of the right-click RMB Icon menu options, see the section on Editing, below.

 

GutterGutter

The Gutter is used to show the line numbers for your code and also to convey some specific pieces of information about the state of the code. Most importantly, if you make a typo or construct the code incorrectly, then the GameMaker Studio 2 IDE will inform you of the issue by flagging the line of code with a red exclamation mark Code Error Icon showing a syntax error. You can then mouse over the symbol to get a brief description of what the issue is:

Script Editor Syntax ErrorYou can find more information on Syntax errors (and general errors when testing or compiling your code) from the following section:

The gutter will also mark any line of the script that has had a breakpoint added. A breakpoint is simply a place in the script where you want the debugger to pause the execution of your game when it is reached. You can toggle a breakpoint from any line of any script or object event by pressing "f9" or using the right-click RMB Icon menu. When you add a breakpoint, it will show up like this in the gutter:

Script Editor Breakpoint MarkerFinally, the gutter will also show any bookmarked items too. To bookmark a line of code simply hold down Control Icon / CMD Icon + Shift Icon + Number (from 0 to 9), and this will permit you to skip back to this line of code from anywhere in the IDE simply by using Control Icon / CMD Icon + Number (from 0 to 9). To delete the bookmark, simply perform the same action as you used to add it on the line of code again. When a bookmark has been added, it will show like this:

Script Editor Bookmark Marker

 

Search / ReplaceSearch / Replace

While working in the script editor, you can press Control Icon / CMD Icon + "F" to open up the Search box or Control Icon / CMD Icon + "H" to open up Search and Replace:

Script Editor Search BoxHere you can perform a local search for the keyword you input and once you have entered your search term, you can then use the arrows at the top right of the search window to skip from one found term to the next in the script. You can change how the search operation is carried out by toggling the following buttons:

Exact Word Icon When you toggle this, the search function will only highlight those strings that match the whole input string. For example, with it off a search for "random" will show up all words that contain this string - like irandom(), or randomise() - while toggling it to on would only show the function random().
Case Sensitive Icon When this option is toggled, you are telling GameMaker Studio 2 to check not only the contents of the search string, but the case too. For example, if you have a sprite called "spr_Dog" and do a search for " dog" with this toggle off, then the sprite string will be highlighted, however if the toggle is on then it won't since "Dog" is no longer considered the same as "dog".

If you have opened the search window using Control Icon / CMD Icon + "F", then the replace functionality will not be visible, so you need to click the Replace button Replace Toggle Icon to open it. Once open, you can then enter a string that will be used to replace any given search string, using the following buttons to perform the action:

Replace Next Icon Clicking this will replace the next search string found in the script with the given replace string. Note that the "next" term is considered the next one after the current cursor position, and you can skip to different ones using arrow buttons at the top right of the search window.
Replace All Icon Clicking this will replace all examples of the search string within the script using the given replace string.

Note that if you want to do a global search (ie: search the whole project rather than the current script or event), then you can press Control Icon / CMD Icon + Shift Icon + "F".

 

 

Main Code EditorMain Code Editor

The main code editor is where you'll write all your code to create the script asset or fill an object event. The actual edition of your code is covered in the section on Editing further down this page.

 

InformationInformation

The information bar at the bottom of the IDE shows you the current line number you are on and the position along the line. It is also where you can see the code helper, which is a line of text that shows the function you are currently editing along with the arguments it requires. As you fill in the function in the editor, the arguments will highlight to show you which one you are currently editing.

Note that any optional arguments in your script functions will be shown with [] brackets around them. If you have used the JSDoc Script Comments within a script asset then the information you have supplied will also show here.

 

You can get further information about using the script and code editors from the following pages: