Difference between revisions of "Give"

From Wiki of ZZT
Jump to navigation Jump to search
(Yes, I verified the #give thing [command] thing in ZZT itself and in the source. You really can be :tooRich)
 
m (→‎Bugs and Quirks: fix typo)
 
(4 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
The syntax for the commands is:
 
The syntax for the commands is:
  
<code>#give <counter> <amount> [<command>]</code>
+
* <code>#give <counter> <amount> [<command>]</code>
<code>#take <counter> <amount> [<command>]</code>
+
* <code>#take <counter> <amount> [<command>]</code>
  
 
The following counters can be modified with '''#give''' and '''#take''':
 
The following counters can be modified with '''#give''' and '''#take''':
Line 16: Line 16:
 
* Z (''Super ZZT'' only)
 
* Z (''Super ZZT'' only)
  
If the result of the command would result in the counter having a value less than 0 or greater than 32767, then the result of the '''#give''' or '''#take''' operation is not stored, and the command is executed instead (if present). The command is usually the name of a [[Label|label]] to jump to, but can also be any other ZZT-OOP operation if desired.
+
If the '''#give''' or '''#take''' would result in the counter having a value less than 0 or greater than 32767, then the result of the operation is not stored, and the command is executed instead (if present). The command can be any ZZT-OOP command, but is usually the name of a [[Label|label]] to jump to, as in the following example:
  
<code>
+
<nowiki>@GemsForHealth
@GemsForHealth<br>
+
#end
#end<br>
+
:touch
:touch<br>
+
#take gems 10 tooPoor
#take gems 10 tooPoor<br>
+
#give health 50
#give health 50<br>
+
#end
#end<br>
+
:tooPoor
:tooPoor<br>
+
You're to poor to buy health!</nowiki>
You're to poor to buy health!
 
</code>
 
  
The command argument is rarely used with '''#give''', though it is available to use
+
The command argument is rarely used with '''#give''', though it is available to use if necessary.
  
== Bugs and Quirks ==
+
==Bugs and Quirks==
  
[TODO: Verify and explain these]
+
* The Time counter actually stores the number of seconds ''elapsed'', not the number of seconds ''remaining''; as such, one has to '''#give''' time in order to reduce the amount of time remaining.
 
+
* The command argument does not need to be prefixed with an '''#'''; for example, '''#take gems 10 put s red key''' is as valid as '''#take gems 10 #put s red key'''.
* The time counter is weird.
+
* ZZT displays sidebar numbers by adding a certain number of spaces to the value in question (two for ammo, one for other values). As such, a '''#take''' which reduces the value by a very large amount will cause a visual glitch. For example, '''#take health 95''' on '''Health: 100''' will display '''Health: 5 0''', while the true value of player health is equal to 5.
* Visual glitches can occur when taking sufficiently large values.
+
** To work around this issue, one should '''#take''' values in smaller quantities.
 +
* Counters in ZZT are signed 16-bit values, as is the parsed integer; overflows and underflows outside the range '''-32768'''..'''32767''' are not checked for.
 +
** The Turbo Pascal standard library function for parsing integers from strings, however, operates in 32 bits; this may cause different classes of bugs on 32-bit overflow. (TODO: what bugs?)
  
 
{{ZZT-OOP navbox}}
 
{{ZZT-OOP navbox}}

Latest revision as of 08:17, 8 February 2021

#give and #take are ZZT-OOP commands for adding and subtracting to counters.

The syntax for the commands is:

  • #give <counter> <amount> [<command>]
  • #take <counter> <amount> [<command>]

The following counters can be modified with #give and #take:

  • Health
  • Ammo
  • Gems
  • Torches (ZZT only)
  • Score
  • Time
  • Z (Super ZZT only)

If the #give or #take would result in the counter having a value less than 0 or greater than 32767, then the result of the operation is not stored, and the command is executed instead (if present). The command can be any ZZT-OOP command, but is usually the name of a label to jump to, as in the following example:

@GemsForHealth
#end
:touch
#take gems 10 tooPoor
#give health 50
#end
:tooPoor
You're to poor to buy health!

The command argument is rarely used with #give, though it is available to use if necessary.

Bugs and Quirks

  • The Time counter actually stores the number of seconds elapsed, not the number of seconds remaining; as such, one has to #give time in order to reduce the amount of time remaining.
  • The command argument does not need to be prefixed with an #; for example, #take gems 10 put s red key is as valid as #take gems 10 #put s red key.
  • ZZT displays sidebar numbers by adding a certain number of spaces to the value in question (two for ammo, one for other values). As such, a #take which reduces the value by a very large amount will cause a visual glitch. For example, #take health 95 on Health: 100 will display Health: 5 0, while the true value of player health is equal to 5.
    • To work around this issue, one should #take values in smaller quantities.
  • Counters in ZZT are signed 16-bit values, as is the parsed integer; overflows and underflows outside the range -32768..32767 are not checked for.
    • The Turbo Pascal standard library function for parsing integers from strings, however, operates in 32 bits; this may cause different classes of bugs on 32-bit overflow. (TODO: what bugs?)