Message box tips and tricks

The message box can be very useful in assisting your development efforts.  This lesson covers some helpful tips and tricks for getting the most out of the message box, not all of which may be completely intuitive.

First - configure the message box options (or: "why does the message box disappear when the script editor opens?")

First - configure the message box options (or: "why does the message box disappear when the script editor opens?")

Before we go further there's one preference I suggest we change.

By default the message box will disappear if you open the scripting editor.  Conversely if it is not visible, and you show it while you are editing it will disappear  when you close the script editor.  I find this behavior very confusing and annoying.  Fortunately you can stop this by opening Revolution Preferences, Script Editor tab and unchecking "Hide Message Box" (1).  You need to uncheck the "Hide Palettes" option too - the reason for this is otherwise, when the palettes hide and show, they will take the focus away from the message box, making it very difficult to work with when using the message box and the debugger.

Now that we've got this configuration issue out of the way, let's continue...

Getting started: Open the message box

Getting started: Open the message box

To show the message box, type command + m (Mac) or Control + m (windows), or select "Show Message Box" from the Tools menu.

The message box contains a button row used to access various features.  The first two buttons (1) access the message box command line in single command or multi-line script command modes.   Since these are what you will probably use the most, we'll start with the command line.

The remaining buttons (2) access other Revolution properties and settings and are covered further below in the section Exploring the Message Bar

Message Box (MB) command line mode (tab 1)

Message Box (MB) command line mode (tab 1)

The message box allows you to execute transcript command and view the results.  It also contains some screens for reviewing other types of information (5) which are covered below in the section "Exploring the Message box"

To show the message box type cmd + m or select "Message Box" from the tools menu.

Type the command you wish to execute at (1), the results are displayed at (2).  If the command you are executing relates to a particular stack, the defaultstack is displayed at (3) (e.g. "put the short name of this stack" would in this example return  "application").  

To show or hide the message box options, cick the toggle at (4).

A couple of useful tips for advanced users:

   Control + a: shifts insert point to start of line

   Control + n: shifts insert point to end of line

You can execute multiple commands (by separating each command with the semi-colon character, e.g.

    beep ; answer "hello"

Message box - Command History

The message box keeps a history of all commands you execute.  Click on the message box command area and click the up or down arrows to cycle through the available commands you have previously executed.

MB command line multi-line (script) mode (tab 2)

MB command line multi-line (script) mode (tab 2)

The second tab (1) allows you to execute multi-line commands. Type your commands into the message box - pressing return while you type will not execute your command. Resize the divider bar (2) if you need more space.  When you are ready, press Enter to execute the script.

One reason why I generally don't use the multi-line mode is that it doesn't keep a history of past events.  Given that most of the time you just want to execute one line commands. For those other situations where you do need say two lines you can use the ";" to concatinate two commands together, e.g.  beep ; answer "hello"  So, while it is handy if you want to copy and paste a script into the message box and execute it there, for the most part, you'll probably be better to use single line command mode.

Advanced tips:

In multi-line message box mode Control + Up or Down key: shifts insert point between the command editing area (top) and results area (bottom)

Why use the message box

During development it is helpful to be able to check program logic or access features in a non-standard way.  The message box makes this easy.

This tutorial reviews how you can use the message box to interact with objects, stacks, and how to use it while debugging.

Using the message box with stacks

Using the message box with stacks

Let's start by taking a look at how the message box works with your stacks.

In this example I have three stacks open "application", "Untitled 1" and "program".  You will often have scripts in the card or stack script of stack that you might want to call for testing purposes.

The name of the stack which will receive commands executed by the message box appears at (3) - at the moment this is the "application" stack (1). Normally this target stack will change automatically as you swap between stack windows, unless you engage the lock (4), as I have here.  Then you can swap to another stack (e.g. the Untitled stack (2) but the message box will still target the Application stack.  Notice that the "Untitled 1" stack (2) is in the foreground, but the message box is still targeting the "application" stack, because I have locked the target.

So if I execute the command "test", it would be sent to the default "application" stack (3).  To be precise, the message will be first sent to the card script, then if it's not handled it perculates up to the stack script.

If you have locked the message box target and you wish to target a different stack, you can manually change the target by clicking on (3) and a dropdown menu of available stacks will appear (as illustrated above).

A  couple of particularly useful transcript commands when working with stacks in the message box are:

topstack - the topmost stack, in this example (2)

defaultstack - the stack which receives message by default, in this example (1).

mousestack - the stack which the mouse is positioned over

Using the message box with objects - command intelligence

Using the message box with objects - command intelligence

Often you will want to access properties or scripts stored in Revolution objects (buttons, fields, groups etc).  The message box provides a special feature called command intelligence designed to help you.

On the right side of the message box command bar window are two options.  Option (1) is "Intelligence acts on mousecontrol", option (2) is "intelligence acts on selectedobject".  

Let's see how these work.

Message box - using command intelligence

Message box - using command intelligence

If you were to turn on "intelligence acts on mousecontrol", position the mouse over say a button, type "name" in the message box, and press return...

Message box - using command intelligence to access an object's properties

Message box - using command intelligence to access an object's properties

... the message box will substitute the command "put the name of the mouseControl"

You can also use this approach to access any custom properties of the object you have set.

The second way you can use command intelligence is to call handlers in an object.

For example I have added the following handler to the script of the "Fred" button:

on helloworld

  answer "hello"

end helloworld

Message box - using command intelligence to access an object's script handlers

Message box - using command intelligence to access an object's script handlers

If I position the cursor over the Fred button and press return in the message box, and because intelligence acts on mousecontrol is on, the "helloworld" command (2) is sent to the "Fred" button and the the script executes displaying the dialog box (3).

Message box and dispatch

Message box and dispatch

If the object you wish to access is not easily selectable (for example it's hidden, or buried inside a complex group) you might find it useful to use the dispatch command in the message box, one advantage of this approach is that if you need to send the command again, you can retrieve it from the message box history.

- You can also include a parameter list with the dispatch command, in this case I am passing in a global variable called gLove

- putting it at the end will return "handled" if the dispatch command was successful.

If you prefer you could also execute this in single line mode by using the concatinate semi-colon char:

put "flowers" into thePeaceMode; dispatch "startworldpeace"  to button "peace" with thePeaceMode ; put it

Message box command line - some useful command examples

Here are some transcript words you may find useful when using the message box:

This command would set the location of whatever object you have selected (the selobj) to 500,500

   set the loc of the selobj to 500,500

This command can be useful when you have a behavior script which you wish to apply to an object.  First select the behavior script button,  type the command in the message box (don't press return),  position your mouse over the object you wish to apply the behavior to, and press return:"

   set the behavior of the mousecontrol to the selobj

Select a stack file, open it:

    answer file a;go it

Sometimes you may not be able to see a stack because it is offscreen.  Us

    set the loc of the topstack to the mouseloc

Editing palettes by pointing at them with the mouse - use the mousestack

Editing palettes by pointing at them with the mouse - use the mousestack

Sometimes you will have a palette window you want to edit, but you don't know what it is called.  In this example we have a palette called References to Review.   Type "toplevel the mousestack", position the mouse over the paletted stack, and click return.

You could also execute "edit the script of the mouseStack" to edit the script of a stack, even if it is in palette mode.

Using the message box while debugging

Remember that you can use the message box even while the debugger is running.  

To illustrate let's look at the following script which I have placed in a button.

on mouseUp

  prepareForWorldPeace

  dispatchHippies

end mouseUp

local sPeaceMode

on prepareForWorldPeace

  put "flowers" into sPeaceMode

  breakpoint

end prepareForWorldPeace

on dispatchHippies

  answer "Peace mode:"&& sPeaceMode

end dispatchHippies

Here we see the script executing, stopped at the point where it has put "flowers" into the local script variable "sPeaceMode"

Because we are in debug mode we won't be able to interact with objects using functions like mousecontrol, so instead let's send an event to the script using dispatch.  The result is illustrated above.

Advanced tip:

If you ever get stuck with an unresponsive script, type command + . (period)

Exploring the message box settings & property tabs

Now that we've covered the message box features related to the command line, let's  take a look at some of the other information screens the message box offers.  

Exploring the MB (tab 3): Viewing global properties

Exploring the MB (tab 3): Viewing global properties

The third tab allows you to view global properties.  Revolution stores a wide variety of default properties.  

Illustrated is the "explictVariables" property, which controls whether Revolution requires variables names to be declared before they are used.  Some properties (like explicitVariables) have a shorter form (explictVars) which will also be listed.

You may also view the value of a property via a command, e.g.

    put the explictVars

... in this case would return: false

Exploring the MB (tab 4): Global Variables

Exploring the MB (tab 4): Global Variables

Tab 4 displays a list of all global variables.  This includes default global vars, as $HOME, which are always prefixed with "$".

Exploring the MB (tab 4): Global variables - arrays

Exploring the MB (tab 4): Global variables - arrays

If the variable you are viewing happens to be an array (in this case the array gEditingA (1) which I have created), then the keys of the array will be displayed in the second column (2).  Click on a key to view the value (3).

Exploring the MB (tab 5): Pending messages

Exploring the MB (tab 5): Pending messages

The fifth tab shows pending messages in Revolution.  

Advanced Tips:

Some plugins (such as glx2Inspector) generate a huge number of these events, so this tab may not be terribly easy to view as it will constantly update.  In this case you might find it easier just to execute the command:

    put the pendingmessages

If you use send messages a lot, you might like to install the Pending Message Manager plugin <http://www.troz.net/rev/stacks/Pending.rev> which optionally filters out all glx messages as well as rev ones.

Exploring the MB (tab 6): Frontscripts

Exploring the MB (tab 6): Frontscripts

Tab 6 shows any Frontscripts you have installed.  These are scripts which are inserted in front of the message passing heirarchy.

Frontscripts and backscripts are usually only used for specialised reasons such as implementing an authoring environment.   If you are new to Revolution you can safely ignore tabs 6 and 7.

Exploring the MB (tab 7): Backscripts

Exploring the MB (tab 7): Backscripts

Tab 7 shows the backscripts you have installed (if any).  These are scripts which are inserted at the bottom of the message passing hierarchy.

Exploring the MB (tab 8): Librarystacks/ stacks in use

Exploring the MB (tab 8): Librarystacks/ stacks in use

Tab 8 shows the stacks which are using (the librarystacks, or the stacksinuse)

You may add, remove or edit a script of a library stack from here. If you are editing a stack script, if you make changes to the script remember you still need to save changes to the stack.

Accessing common operations for open stacks

Accessing common operations for open stacks

As a slight digression, you can also access library stacks from the Application Browser window (Tools menu -> Application Browser).  Right click (Mac: Control click) on a stack in the list to access a context menu.  You can access a variety of commonly used features from this menu.

Message box extras - Message Box Picker 1.1

Advanced users may find the following message box plugin useful:

"This utility reorganizes the message history and puts the messages into chronological order, deletes any doubles and installs in the message box a drop-down menu that can be completely personalized and that makes it possible to bring up or to send a message with one mouse click. Bilingual utility (installer and uninstaller.) Help stack is included. Identical appearance on all platforms."

Click here for website or here to download

Message Box Picker in action

Message Box Picker in action

After installation of the plugin, notice the script icon is added to the message box.  Click this for a drop down list of commands you have issued from the message box.

10 Comments

Alejandro Tejada

Very enlightening tutorial!
Really useful link to plug-in.

Rodney Tamblyn

Thank you!

paulo gomes

Hi,
Very interesting article. However, I could not find what I'm looking for (I have only few months of Livecode experience): how to clean the Message Box.
I was testing a plug in that I bought and I use the Message Box for that purpose.
After, it seems that Livecode had the Message Box single line command "attached" to one of the cards in the App I'm developing because every time the logic launches that card, the Message Box appears.
Of course I already select the command and deleted but it always come back.
Any ideas why is this hapenning and how can I get rid of the message box?
Thanks for the help.
Paulo

paulo

Hi,

Somehow when I launch one card for the main stack (only that card) the Message Box pops up with the last single line command I executed using the message box.
This happens only with one specific card and I have no idea why.
Is there a way to clean whatever is in the message box? I tried everything I coukld find in the Tutorials: ctrl-U, delete the single line command using the backspace or delele keys but always when that card runs, the message box pops up again.
This does not affect the deployed application since the message box belongs to the IDE, not the application. I also tried use an older Livecode version (says 5.5.1) and it happens.
It borthers while developing keep closing a dialog window when you no longer need it.
Do you have an idea what to do?

Thanks,
Paulo

Hanson Schmidt-Cornelius

Hi Paulo,

the message box appears when a "put" command is used that does not assign a value to a specific variable or other storage location. For example if you had code that executed the following syntax:

put 3

This launches the message box and displays the value: "3".
The message box is not displayed if you use something like the following:

local tSomeStorage
put 3 into tSomeStorage

The value "3" is assigned to the variable: "tSomeStorage".

There is currently no way of switching this behaviour off, but if you can track the "put" statements down that do not assign a value, then the message box should not appear. If the message box appears as a result using a plugin, then you may have to contact the person who developed the plugin and request them to address the problem.

Kind Regards,

Hanson

breakpoints

Hi

Sometimes when I have inserted breakpoints (i.e., I have produced red 'dots' at the side of the code on particular lines) the program does not stop at those points when I am running.

This is despite the fact that the program definitely executes those lines when running and I also make sure to have 'script debug mode' switched on.

Can anyone enlighten me as to this apparent inconsistency?

Thanks
Ian S

Hanson Schmidt-Cornelius

Hi Ian,

that is strange. If you use breakpoints in the way you describe, then you should hit them.
Have you tried using the "breakpoint" command rather than breakpoints.

If you are still having problems with the issue and you are able to reproduce it in a sample stack, then it would be great if you could contact us with a recipe to reproduce the problem.

You can contact our support at: support@runrev.com
You can create a bug report at: quality.runrev.com

Kind Regards,

Hanson

Mark Rauterkus

On a laptop, I don't have an "ENTER" key.

Pushing the RETURN key when in the message box gives a new line.

How do I click an "enter key" so as to execute a script when there is no "Enter" key?

Perhaps a CTRL ENTER within the message box would send an ENTER key message so that scripts could execute? Some solution is needed. Enlighten me please.

Hanson Schmidt-Cornelius

Hello Mark,

the first alternative is to switch to the single-line message box. In that mode, you can execute one line at a time with the "Return" key.
If you do need the multi-line message box, then you can press either "alt-Return" or "ctrl-Return", depending on what operating system you are using.

Kind Regards,

Hanson

Mark Davis

On a macbook, trying to get the multiline mb to execute confused me for a while. For anyone else reading this, you might need to press fn-return for it to work.

Add your comment

E-Mail me when someone replies to this comment