Zap: Difference between revisions

From Wiki of ZZT
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:zap}}
{{DISPLAYTITLE:zap}}
'''#zap''' and '''#restore''' are [[ZZT-OOP]] commands for disabling labels. '''#zap label''' will disable the first active occurence of label by turning it into a comment, while '''#restore label''' will turn all comments "label" back into labels. (with caveats - see below). They allow selective disabling of labels on a given [[Object]], as well as multiple meaningful destinations of the same label name.
'''#zap''' and '''#restore''' are [[ZZT-OOP]] commands for disabling labels. '''#zap''' will disable the first active occurence of label by turning it into a comment, while '''#restore''' will turn all comments "label" back into labels. (with caveats - see below). They allow selective disabling of labels on a given [[Object]], as well as multiple meaningful destinations of the same label name.


== Label restoration quirks ==
== Syntax ==
* <code>#zap <label></code>
* <code>#restore <label></code>
 
== Bugs/Quirks ==
 
* '''#restore''' does not work for labels located on the first line, as it relies on a newline preceding the label to locate it. For example, the following will not work correctly, because the '''touch''' label is on the first line of the program.
 
'touch
This will never be called!
#end
:shot
#restore touch
 
This can be worked around by using any non-label for the first line (a command like '''#end''', a program name, or even a blank line).
 
*'''#restore''' fails to restore labels after the first zapped-matching occurence if the line succeeding them starts on an alphabetic character or an underscore. For example:
 
#end
'touch
/iFirst line.
#end
'touch
Second line.
#end
:shot
#restore touch
 
This code will only restore the ''first'' '''touch''' label upon being shot; the ''second'' label will only be restored upon being shot a second time. This is because the second succeeding line starts with an alphabetic character '''S'''. Conversely, the following code:
 
#end
'touch
/iFirst line.
#end
'touch
/iSecond line.
#end
:shot
#restore touch
 
will restore ''both'' '''touch''' labels upon being shot just once. This is because the succeeding lines start with a non-alphabetic character ('''/''').


* '''#restore''' does not work for labels located on the first line, as it relies on a newline preceding the label to locate it.
* '''#restore''' fails to restore labels after the first zapped-matching occurence if the line succeeding them starts on an alphabetic character or an underscore.
* '''#zap restart''' and '''#restore restart''' will always edit the second character of the targetted Object's code into <code>'</code> or <code>:</code> respectively.
* '''#zap restart''' and '''#restore restart''' will always edit the second character of the targetted Object's code into <code>'</code> or <code>:</code> respectively.
* '''#zap''' and '''#restore''' edit the code of an Object - this means that, if the code is being used by other [[Bind|bound]] Objects, labels will be changed on all of them.
* '''#zap''' and '''#restore''' edit the code of an Object - this means that, if the code is being used by other [[Bind|bound]] Objects, labels will be changed on all of them.
* '''#zap''' accidentally allows for remotely zapping labels on other targets - for example, '''#zap all:label'''. '''#restore''' also allows for this, but only on the first occurence.
* Due to a code quirk, '''#zap''' allows remotely zapping labels on other targets - for example, '''#zap all:label''' will zap one occurence of '''label''' on every object on the board.
** This means one could use '''#restore self:label''' to only restore the first zapped-matching label in an object.
** '''#restore''' also allows doing this, but only for the first occurence of a given zapped label on every object.
*** One can, therefore, use '''#restore self:label''' to only restore the first zapped label in an object.


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

Latest revision as of 17:13, 29 September 2022

#zap and #restore are ZZT-OOP commands for disabling labels. #zap will disable the first active occurence of label by turning it into a comment, while #restore will turn all comments "label" back into labels. (with caveats - see below). They allow selective disabling of labels on a given Object, as well as multiple meaningful destinations of the same label name.

Syntax

  • #zap <label>
  • #restore <label>

Bugs/Quirks

  • #restore does not work for labels located on the first line, as it relies on a newline preceding the label to locate it. For example, the following will not work correctly, because the touch label is on the first line of the program.
'touch
This will never be called!
#end
:shot
#restore touch

This can be worked around by using any non-label for the first line (a command like #end, a program name, or even a blank line).

  • #restore fails to restore labels after the first zapped-matching occurence if the line succeeding them starts on an alphabetic character or an underscore. For example:
#end
'touch
/iFirst line.
#end
'touch
Second line.
#end
:shot
#restore touch

This code will only restore the first touch label upon being shot; the second label will only be restored upon being shot a second time. This is because the second succeeding line starts with an alphabetic character S. Conversely, the following code:

#end
'touch
/iFirst line.
#end
'touch
/iSecond line.
#end
:shot
#restore touch

will restore both touch labels upon being shot just once. This is because the succeeding lines start with a non-alphabetic character (/).

  • #zap restart and #restore restart will always edit the second character of the targetted Object's code into ' or : respectively.
  • #zap and #restore edit the code of an Object - this means that, if the code is being used by other bound Objects, labels will be changed on all of them.
  • Due to a code quirk, #zap allows remotely zapping labels on other targets - for example, #zap all:label will zap one occurence of label on every object on the board.
    • #restore also allows doing this, but only for the first occurence of a given zapped label on every object.
      • One can, therefore, use #restore self:label to only restore the first zapped label in an object.