# new RezCard()
Represents a card in the Rez game engine. Cards are the primary content containers that display narrative text, choices, and interactive elements to the player.
Cards exist within scenes and follow a defined lifecycle:
- start - Card is initialized and becomes the current card
- ready - Card is rendered and ready for player interaction
- finish - Card is being replaced or scene is ending
Template System
Cards use templates to render their content:
$content_template- The primary face template (required)$back_template- Optional back-face template for use in stack layoutscurrent_face- The active face name (default"content")faces- Set of face names declared on this card (default#{:content, :back})
Scene Relationship
Cards have a transient reference to their containing scene, set when the scene
calls playCard(). In single layout mode, this reference becomes stale when
the card is replaced. In stack layout mode, the reference persists while the
scene is running.
Block System
Each card is wrapped in a RezBlock for rendering. The block manages the card's position in the layout and handles flip state transitions.
Event Handlers
Cards can define event handlers using the on_<event> attribute naming convention:
on_start- Called when the card becomes the current cardon_ready- Called after the card is renderedon_finish- Called when the card is being replacedon_<custom>- Custom events triggered by game logic
Extends
Methods
# bindAs() → {string}
Returns the binding identifier used in template rendering. When a card is rendered, its properties are bound to the template context under this name.
"card"
string
# constructor(id, attributes)
Creates a new card instance with null scene and block references
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string
|
unique identifier for this card |
attributes |
object
|
card attributes from Rez compilation |
- Overrides:
# current_block(block)
Sets the RezBlock instance for this card. Called by the scene when adding the card to the view layout.
Parameters:
| Name | Type | Description |
|---|---|---|
block |
RezBlock
|
the block to set |
# getViewTemplate(faceopt) → {function}
Returns the template for the specified face. The face name maps to a compiled
template attribute: face "content" → $content_template, face "back" → $back_template, etc.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
face |
string
|
<optional> |
the face name to get the template for. Defaults to the card's current_face attribute. |
if the card has no template for the requested face
Error
the template function for rendering this card's current face
function
# handleCustomEvent(event_name, evt) → {object}
Handles custom events by looking up and invoking the appropriate event handler.
Event handlers are defined using the on_<event_name> attribute naming convention.
Returns an error object with a descriptive message if no handler is found.
Parameters:
| Name | Type | Description |
|---|---|---|
event_name |
string
|
the name of the custom event to handle |
evt |
RezEvent
|
the event object containing event data |
the result from the event handler, or an error object if no handler exists
object