Label: Difference between revisions

From Wiki of ZZT
Jump to navigation Jump to search
Asie (talk | contribs)
Created page with "Labels allow associating a specific location in the object's code with a specific message. {{ZZT-OOP navbox}}"
 
Asie (talk | contribs)
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Labels allow associating a specific location in the object's code with a specific message.
Lines of ZZT-OOP beginning with a colon <code>:</code> are '''labels'''.
 
Labels allow associating a specific location in the object's code with a specific '''message'''. The object will move program execution to such a location in the following two cases:
 
* when explicitly requested by an object, including a different object, using [[Send|#send]];
* when the game engine causes one of the built-in messages to be sent to the object.
 
Labels should consist of Latin alphabet letters (A - Z) and underscores. They are not case sensitive - <code>TOUCH</code> , <code>Touch</code> and <code>touch</code> refer to the same message.
 
The first occurrence of a label in the code is always used as the destination. To allow using additional occurrences of a label, labels can be [[Zap|zapped]], where they act as [[Comment|comments]] and will be ignored by [[Send|#send]] - for example, <code>'shot</code> is the zapped form of the <code>:shot</code> label.
 
== Bugs/Quirks ==
 
* Labels must not be placed on the first line of an object's code; such a label will be ignored.
* Only characters <code>A, B, C, ..., Y, Z, _</code> are handled fully correctly by labels. This has some interesting side effects:
** Numbers <code>0, 1, ..., 9</code> can be used as part of a #send or #zap argument; however, any additional numbers at the end of a given label will be ignored.
*** For example, the message <code>touch</code> will match the label <code>:touch</code> as well as the labels <code>:touch1</code> and <code>:touché</code>, but not the labels <code>:toucha</code> or <code>:touch_1</code>.
*** Similarly, the message <code>only1</code> will match the label <code>:only1</code>, as well as <code>:only11</code> and <code>:only12</code>.
*** Notably, this rule does ''not'' apply for the [[Restore|#restore]] command for the ''second'' and additional label occurrences, where an ''exact'' string match is required.
** Non-alphanumeric characters, such as <code>é</code>, will be ignored just like numbers, but cannot be used as part of a #send, #zap and #restone argument.
*** For example, while you can define a label <code>:touché</code>, <code>#send touché</code> is parsed as <code>#send touch</code>.


{{ZZT-OOP navbox}}
{{ZZT-OOP navbox}}

Latest revision as of 07:56, 1 March 2026

Lines of ZZT-OOP beginning with a colon : are labels.

Labels allow associating a specific location in the object's code with a specific message. The object will move program execution to such a location in the following two cases:

  • when explicitly requested by an object, including a different object, using #send;
  • when the game engine causes one of the built-in messages to be sent to the object.

Labels should consist of Latin alphabet letters (A - Z) and underscores. They are not case sensitive - TOUCH , Touch and touch refer to the same message.

The first occurrence of a label in the code is always used as the destination. To allow using additional occurrences of a label, labels can be zapped, where they act as comments and will be ignored by #send - for example, 'shot is the zapped form of the :shot label.

Bugs/Quirks

  • Labels must not be placed on the first line of an object's code; such a label will be ignored.
  • Only characters A, B, C, ..., Y, Z, _ are handled fully correctly by labels. This has some interesting side effects:
    • Numbers 0, 1, ..., 9 can be used as part of a #send or #zap argument; however, any additional numbers at the end of a given label will be ignored.
      • For example, the message touch will match the label :touch as well as the labels :touch1 and :touché, but not the labels :toucha or :touch_1.
      • Similarly, the message only1 will match the label :only1, as well as :only11 and :only12.
      • Notably, this rule does not apply for the #restore command for the second and additional label occurrences, where an exact string match is required.
    • Non-alphanumeric characters, such as é, will be ignored just like numbers, but cannot be used as part of a #send, #zap and #restone argument.
      • For example, while you can define a label :touché, #send touché is parsed as #send touch.