send

From Wiki of ZZT
Revision as of 06:40, 22 September 2021 by The Green Herring (talk | contribs) (→‎Quirks: #send command length limit)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

#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.

Syntax

  • Object sending a label to itself: #send self:<label>
  • Object sending a label to multiple objects (and possibly itself as well): #send <all|others|name>:<label>

#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 #die.

Quirks

  • A locked object will not receive external messages, but it can still #send messages to itself. This includes when sending to all objects with #send all:label.
  • Following the #send (excluding the space after it) or # in the #label shortcut, 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 #label shortcut is used and the truncated version of the label does not exist. The engine will also truncate any name:label, all:label, others:label, or even self:label command 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.