"Lock and Key: Variable": Snowman (v1.3)


"Lock and Key: Variable" demonstrates how to create the effect of picking up a key and unlocking a door. In this example, the key is a variable (s.key) and does not initially exist in the Start passage.

When the link "Pick up the key" is clicked, s.key is changed to the value true and the door link changes from its initial response of "Locked Door" to a link to the passage Exit.

Live Example

Download: Live Example

Twee Code

:: StoryTitle
Lock and Key: Variable in Snowman

:: Start
- [[Front Room]]
- [[Back Room]]

:: Front Room
<% if (s.key) { %>
<% } else { %>
*Locked Door*
<% } %>

- [[Back Room]]

:: Back Room
<% if (!s.key) { %>
- <a href="javascript:void(0)" class="key-item">Pick up key</a>
<% } else { %>
There is nothing here.
<% } %>

$(function() {
    $('.key-item').click(function() {
        s.key = true;
        $(this).replaceWith('<span>You have a key.</span>');

- [[Front Room]]

:: Exit
You found the key and went through the door!

Download: Twee Code

See Also

Setting and Showing Variables

results matching ""

    No results matching ""