bind

From Wiki of ZZT
Revision as of 09:16, 30 January 2026 by Quantum (talk | contribs) (Reorganize a bit, add info on what binding actually is and how to pre-bind properly)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

#bind is a ZZT-OOP command which allows replacing the currently executed Object code with that of a different Object present on the board.

Binding objects together causes them to share a single copy of the exact same program. This makes #bind useful for saving space when objects need to have the same code. However, this also means that if one of the objects runs a command that alters the code (#zap or #restore), the other objects will also be affected by that change.

While it is common for objects that use #bind to have it be their only command, that does not need to be the case. Objects can use #walk before binding to set a different flow direction, #cycle to give themselves a different speed, /i to delay the start of execution, or whatever else suits one's needs.

With external editors it is possible to "pre-bind" an object to another without needing to use this command (even if the other object doesn't have a proper name!). However, care must be taken to make sure the objects are in the correct stat order, or else memory corruption may result. This is because the object that actually contains the code must appear before any bound objects in the stat list; using ZZT's built-in #bind manages this for you, but authors using pre-bound objects must manage the stat order themselves.

Syntax

#bind <object name>

Bugs

  • In unmodified ZZT, #bind always causes the memory allocated by previously used code to be freed, without checking if the code is also bound to other Objects. As this does not clear the memory or invalidate the pointer to said code, execution can continue as normal. However, any dynamic memory allocation - such as opening text windows - may cause corruption and instability.