Key (thing)

From MZXWiki
Revision as of 01:15, 14 June 2025 by Lachesis (talk | contribs) (Created page with "{{ID |name = Key |id = 39 |robotic = Key |color = none |param = 0 |idchar = 12 |score = |pushable = all |effect_touch = '''If keys aren't full''': give held key, become Space, move Player;<br>'''Otherwise''': block Player }} Category:MegaZeux Category:MegaZeux built-in objects Category:Items Key is a built-in item. When touched by the Player, the Player is given a held key, SFX 8 (Key) plays, the Key is repla...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Key # 39 Id39.png
Robotic name Key
Default color none
Default param 0
ID char 12 (#39)
Attributes Pushable: all
Effect when
touched
If keys aren't full: give held key, become Space, move Player;
Otherwise: block Player

Key is a built-in item. When touched by the Player, the Player is given a held key, SFX 8 (Key) plays, the Key is replaced with a Space, and the Player moves on top of the new Space. If the Player already has 16 held keys, the Key plays SFX 9 (Full Keys) and acts as a wall that blocks the Player from moving.

The color of the held key given by a Key is derived from the foreground color of the Key, i.e. if the Key has color ce2, the Player will receive a held key of color 2 when the Key is collected.

Held keys

The Player can have, at most, 16 held keys of any color. Keys currently held by the Player can be viewed using the game menu (Enter) in most games.

When the Player touches a locked Lock, Door, or Gate, held keys are used to unlock and open them. The Robotic commands GIVEKEY, GIVEKEY ELSE, TAKEKEY, and TAKEKEY ELSE can be used to interact with held keys. The Robotic command OPEN may consume held keys when used to open locked Doors/Gates.

Simulating ZZT keys with Robotic

At most one Key of each color can be held at a time in ZZT. This can be simulated in MegaZeux by using Robots instead of built-in Keys and the following program:

end
: "touch"
takekey "this_color" else "give"
givekey "this_color"
sfx 9
end
: "give"
givekey "this_color"
sfx 8
die as an item

Counting held keys with Robotic

Counting the Player's current held keys can be useful for implementing a custom HUD. The current held keys can be counted with this Robotic fragment:

set "commands" to "min&commands&,1000"
set "local" to 0
: "count"
set "num_keys_&local&" to 0
loop start
takekey "local" else "all_keys"
inc "num_keys_&local&" by 1
loop for 15
: "all_keys"
if "num_keys_&local&" = 0 then "no_giveback"
loop start
givekey "local"
loop "('num_keys_&local&'-1)"
: "no_giveback"
inc "local" to 1
if "local" < 16 then "count"

ZZT connection

In ZZT, the equivalent element to Key is zzt:Key. In ZZT, the Player can only hold 7 keys (not counting buggy black keys), and can hold at most only one key of each color.