Key (thing): Difference between revisions

From MZXWiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 12: Line 12:
[[Category:MegaZeux]] [[Category:MegaZeux built-in objects]] [[Category:Items]]
[[Category:MegaZeux]] [[Category:MegaZeux built-in objects]] [[Category:Items]]


[[Key (thing)|Key]] (ID 39, <code>Key</code>) is a [[built-in]] [[Items|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.
[[Key (thing)|Key]] (ID 39, <code>Key</code>) is a [[built-in]] [[Items|item]].
 
When touched by the [[Player]], the Player is given a [[held key]], the [[Message Line|message]] "You grab the key." displays, [[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 message "You can't carry any more keys!" displays, SFX 9 (Full Keys) plays, and the Key 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 <code>ce2</code>, the Player will receive a held key of color 2 when the Key is collected.
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 <code>ce2</code>, the Player will receive a held key of color 2 when the Key is collected.

Revision as of 01:37, 14 June 2025

Key # 39 Id39.png
Robotic name Key
Default color none
Default param 0
ID char 12 (#39)
Attributes Pushable: all
Effect when
touched
If held keys aren't full: give held key, become Space, move Player;
Otherwise: block Player

Key (ID 39, Key) is a built-in item.

When touched by the Player, the Player is given a held key, the message "You grab the key." displays, 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 message "You can't carry any more keys!" displays, SFX 9 (Full Keys) plays, and the Key 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

(It is not possible to make these ZZT "keys" pushable without breaking how the Player interacts with them.)

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 "max&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.