#send is a ZZT-OOP command that provides a means of directing one or multiple objects. When an object receives a message from #send, it checks its program for a matching label, and if found, continues program execution from that point. ZZT's manual compares it to the GOTO statement in BASIC.
Objects can send messages to themselves to control their own program flow, as well as send to other objects. An object can manage multiple instances of a label with #zap and #restore, allowing different reactions to the same received message string. If an object needs to perform a task without interruption, it can turn off all incoming messages with the #lock command.
- Object sending a label to itself:
- Object sending a label to multiple objects (and possibly itself as well):
#send is unique among ZZT-OOP commands in that the command part can be omitted as a shortcut:
#label is functionally identical to
#send self:label, so long as
:label exists somewhere in the code and label isn't the name of a command like
- A locked object will not receive external messages, but it can still #send messages to itself. This includes when sending to all objects with
- Following the
#send(excluding the space after it) or
#labelshortcut, a message cannot exceed 20 characters in length. If it does, the engine will truncate the message to 20 characters and attempt to execute the resulting command. An error message will be thrown only if the
#labelshortcut is used and the truncated version of the label does not exist. The engine will also truncate any
others:label, or even
self:labelcommand that exceeds 20 characters; it will then either execute the truncated label in the target object, or attempt to jump to a label with the truncated target name, depending on where the command is cut off, without throwing an error message if neither such label can be found.