A newer version of Max is available. Click here to access the latest version of this document.
Tutorial 2: Bang!
The bang message
Open the tutorial.
In this tutorial, we will work with the bang message as a way to follow messages through the connections in a Max patcher.
This simple patcher will let us look at how to generate messages in Max, and how these messages execute through a patcher in a pre-defined order.
Looking around
Take a look at the patcher 02mBang. At the left side of the patcher window is a very simple patch, with a button UI object connected to a print object. If you click on the button (marked by the comment, "Click me!"), you will see that the Max window displays a bang message – the output from the button.
The bang message has a specific use within Max – it's the message that tells many objects to do that thing you do. As a result, sending the bang message to other objects will normally cause them to send messages from their outlets. In the second part of the patcher (to the right), there is a button (labeled "Now click me!") connected to a message box (with the message Gotcha!), which is subsequently connect to a print object. If we click on the message box, we can see the Gotcha! message sent to the Max window – just like in the previous Tutorial. Now, click on the button object. We see the same Gotcha! message appear in the Max window. How did that happen?
Let’s follow the messages. First, clicking on the button object sends a bang message from its outlet. This message follows the patch cord to the inlet of the message box. When the message box receives the bang message, it performs its task – it sends out its message. Hence, the Gotcha! message is sent from the message box outlet to the print object, where it is printed to the Max window.
Most Max objects (the message box and button included) will interpret a bang as an instruction to perform their main task using whatever information they have available. We'll see in subsequent tutorials how this plays out with objects that manipulate numbers and other items of data in the Max universe, but for now it's worth observing that since the primary function of the message box is to construct and pass messages, sending a bang to any message box will cause that object to output whatever message is stored in it.
Following messages through connections
The bang message is not only useful for triggering message boxes – as we mentioned above, it can act as a trigger for many other objects as well. Click on the button at the top-right of the third patch – it is connected to a second button that is triggered by a bang message, which then sends its message (bang) to the print object.
Note that this print object has an argument after it ("one"). If you look at the Max window, you will see that instead of the word "print" appearing in the object column, the argument to the print object appears - "one". This is useful for debugging Max patchers, as it allows you to create multiple print objects with custom labels to differentiate them from one another in the Max window.
Now unlock the patcher, and connect the outlet of the top button to the lone button to its left. Notice that this doesn’t break the connection that already exists; outlets can be connected to more than one object, and the same message will be sent down each of the patch cords. Lock the patch and click on the top-most button. The bang gets sent to both button objects, and each of them produces a bang message of their own.
By a similar token, multiple patch cords can also be connected to a single inlet of an object. In this case, both of our button objects are connected to a single print object. When you click on the top button, the output of both buttons that receive bang messages are routed to the print object, and two bang messages are displayed in the Max window.
The next patch over demonstrates both of these principles. Clicking the button at the top of the patch sends three bang messages to the Max window (through a print object labelled "several"). The print object receives a bang from both of the "second-tier" button objects (triggered by our topmost button) as well as a single bang from the top button itself, connected directly to the print object.
We can take this idea further with the right-most patch. It has a number of message boxes, all connected to a single print object named “many”. Each message box has a button attached to it, and a higher-level button controlling them all. You can make individual message box objects print their message by either clicking on the message box itself, or by clicking on their attached button objects. If you want to trigger all of the message boxes at once, you can click on the top-most button.
When you hit the top button, notice the order in which the messages are displayed in the Max window. The messages are not in an arbitrary order – they are generated based on the spatial organization of the objects in the patcher, executing from right-to-left. We will explore the details of message ordering in a future tutorial, but it is useful to understand that messages are sent in right-to-left order when a single object is connected to many other objects.
Unlock the patch, and add several more button objects. You can do this by bringing up the palette and selecting the button object's icon, or by simply clicking the 'b' (for button) key on the keyboard in an unlocked patcher. Connect them to other button objects on that right-hand patch. Try different combinations of multiple outlet connections and multiple inlet connection. As you connect each button, try to guess which messages will display and what order they will be sent to the Max window.
Conclusion
The bang message is among the most powerful messages in the Max environment; it causes other objects to trigger their output, and can be used to create matrices of connections that produce the desired output. We’ve also seen that both inlets and outlets can have multiple connections, and that these connections output their messages in a predictable order. We’ve also seen that some objects, such as the print object, can be assigned an argument, which causes the object to change its behavior. An argument to the print object allows you to identify the source of messages printed to the Max window.

See Also

Name Description
button Flash on any message, send a bang
print Print any message in the max window
message Send any message