MiceOnABeam Product Documentation

Modified: 3/18/2016 3:10 PM
Recently changed articles You can subscribe to this wiki article using an RSS feed reader.

Using the Code Editor

MiceOnABeam has a built-in code editor to enter in LSL event-handling code at various points within the script model. It provides the following features:

  • Code completion for LSL functions & keywords as well as variables & functions within scope
  • Complete LSL code syntax checking including type-checking
  • LSL code syntax highlighting
  • Hover tooltips
  • Code auto-indentation
  • Selection highlight
  • Find/Replace of text
  • Editing code via an external text/code editor
  • Undo/Redo of coding changes
  • Cut/Copy/Paste of code
  • Code & line selection

Code Completion

As LSL code is being typed into the code editor, LSL function names, constants, keywords and variables & functions within scope are scanned for on the current line. A list of possible matches is displayed for the closest partial match. The type/calling signature and description (in most cases) of the currently selected item is also provided.

When the list of possible matches is shown, a list item can be selected by either using the up/down cursor keys or selecting an item from the list with the mouse. Once an item is selected (i.e., highlighted) it can be chosen for insertion into the code by using either the Tab or Enter key. Alternatively the selected item can be double-clicked.



Syntax Checking

The Code Editor provides a complete syntax checker that will check the code for proper LSL syntax and ensure that the correct number and type of parameters have been passed to an LSL function. It also flags certain LSL statements that cannot be used in MiceOnABeam, and ensures that only the appropriate statement types are used within a particular code segment. For example, the LSL code entered in for a Guard Condition must return a value.

Error statements are inserted as comments directly within the code and prefixed with //ERR:  An upwards pointer indicates the approximate position in the line above where the error occurred. Note that the error lines cannot be edited nor individually deleted, but will be automatically cleared when the error has been corrected and the code has been rechecked. However all error messages inserted in the code can be removed at any time via the context menu item Clear Errors.

A dialog field containing LSL code is automatically checked either whenever that field is left, such as when clicking in a different field or when the OK button is selected depending on the dialog. If there are errors when the OK button is selected, a WARNING dialog will be issued indicating that there are unresolved coding errors. At this point the errors can be ignored by selecting the Yes button and the code saved regardless, or the Cancel button can be clicked to cancel the save.

References to undeclared LSL variables and functions are detected and flagged as errors. In addition if a variable is declared and never used, or used before it has been initialized, a warning will be issued.  Local variables that are multiply declared within the same local scope of an LSL code segment will also be flagged as errors.

Finally, obvious cases of unreachable code are flagged as well.



NOTE: LSL permits local variable declarations to override (i.e., use the same name as) global variable declarations and so in MiceOnABeam state variables and functions can override those defined in a higher scope. Therefore MiceOnABeam will not flag a local variable or function declaration which overrides a higher scoped one defined as a state variable, function or Custom Global.

In general overriding variables and functions should be avoided as their models and LSL code are harder to follow and understand.


Syntax Highlighting

The various elements comprising LSL code within the Code Editor are highlighted with unique colors.

In addition, placing the cursor to the right of a starting or ending bracket including (), {}, [] and <> will highlight both brackets.



Hover Tooltips

A pop-up help tip is shown whenever the mouse cursor hovers over a variable, constant or function, showing it's type signature and description (if any).




Code lines can be indented by using tabs. When the Enter key is pressed on an indented line of code, a new line will be entered, and will be indented to the same position as the previous line.

Multiple lines of code can be indented together by simply selecting the text across the lines of interest, and then tabbing the desired number of times. Note that pressing and holding the Shift key prior to tabbing, will shift the selected lines to the left.


Selection Highlight

Whenever text is selected in the Code Editor, other instances of that same text will also be highlighted. This feature can be disabled by de-selecting Show extended selection highlighting in the Code Editor pane of the Options dialog.

In addition you can also tab (or Enter key) forward or backward (using the Shift key) between highlighted items.




The Find/Replace dialog box can be opened by pressing CTRL-F to find some text or CTRL-H to both find and replace some text. You can also first select some text in the Code Editor prior to pressing the keys in order to pre-fill the Find what: field in the Find/Replace dialog.

Within the Find/Replace dialog box you can select various options for the search and click the appropriate button to either find the next occurrence of the text (Find Next), replace the found text with the text in the Replace with: field (Replace) or replace all occurrences of the text with the replacement text (Replace All).

There is a single Find/Replace dialog box for all open LSL Code Editors, however the dialog box is linked to only a single code editor at a time. This link is shown in the title bar of the dialog. You can switch the Find/Replace dialog box to another code editor by simply clicking within the desired editor or pressing CTRL-F or CTRL-H from it.

If you are in the Find/Replace dialog box and wish to bring up the hidden Replace buttons simply press CTRL-H.

Note that the Find/Replace is not available for certain single-line code entry fields associated with State Variable & Functions, Component Configuration and LSL Action editors.


Using an External Code Editor

As there are several very good code editors for LSL on the market, (see Alternate Editors), MiceOnABeam can also be configured to invoke any external editor. In this way, individual code segments within the model can be automatically sent to an external editor, modified and saved, and then returned to and saved within the model.

To enable MiceOnABeam to use an external code editor, the Code Editor settings within the Options dialog (accessible from the Tools menu in the Main Program window) must be configured. Here, under the External Editor section, the Command field must be filled in with the complete path name of the editor's executable. Optionally, the Arguments field can also be filled in as needed.



Once configured, the external editor can be opened for a code segment by selecting Open External Editor (or CTRL-E) from the Code Editor's context menu.

The external editor will then open with the field's contents inserted. After the code is edited, it must be saved in the external editor, and then the editor closed. The modified code will then replace the previous code in the model and can be saved by selecting the OK button.

If there are problems with the external editor which does not permit a graceful return to MiceOnABeam, then the external edit can be canceled by clicking the Cancel Edit button on the dialog that is presented during external editing.



Code & Line Selection

Selections of code can be made for cut, copy, paste, deletion, replacement and tabbing, through the standard method of mouse clicking at the start of the selection and dragging left or right to the last character for the selection. Tabbing after making a selection, will select and tab all lines, unless only a partial selection was made within a single line, in which case the selection will be replaced with a tab character.

A line of code can also be fully selected by simply clicking on its line number. Multiple lines of code can be selected by clicking down, dragging the mouse cursor across the range of line numbers to be selected and then releasing the mouse button. Shift-clicking over a line number, will extend the selection to the corresponding line.

Code Editor Context Menu Items

Selecting Undo, will undo the last coding change. Selecting Redo, will redo the last undone coding change. The program can undo the last ten coding changes.

Copies the selected code to the system clipboard, and then deletes the selected code.

Copies the selected code to the system clipboard.

Inserts text from the system clipboard.

Deletes the selected code.

 Search for the next occurrence of the "Find what" text and select it.

Replace the currently selected text with the "Replace with" text and then search for the next occurrence of the "Find what" text and select it.

 Selects all code in the Code Editor.

 Performs a syntax check of the LSL code in the Code Editor.

 Deletes any error statements that may have been inserted in the code.

Opens a previously configured external editor to edit the LSL code.

Lists the set of built-in LSL Actions which you can insert into your code. See LSL Actions for full details.

Opens the LSL Action Configuration Wizard for the LSL Action corresponding to the Action directive adjacent to the cursor.

Shows the LSL code that will be generated for the LSL Action directive adjacent to the cursor. If desired the code can be inserted in the current code editor replacing the action directive and customized further. Note that in this case the LSL Action Configuration Wizard will not be able to be used to re-edit the generated code.

Home: MiceOnABeam Product Documentation Copyright © 2010-2018 MiceOnABeam Software