Your browser lacks required capabilities. Please upgrade it or switch to another to continue.
Loading…
/% it is always a good idea to initialize your variables, but with arrays it is particularly important %/
<<set $inventory to []>>
<<set $chest to ['a shield', 'a suit of armor']>>
<<set $chestOpen to false>>You are currently carrying:
/% if the inventory contains nothing, show "nothing" %/\
<<if $inventory.length is 0>>\
nothing.
<<else>>\
/% the Array#join() method combines all array elements into a single string, with each element separated by the argument given %/\
<<= $inventory.join(', ')>>.
<</if>>
-----
/% we use the Array#push() method to add new items to our inventory array %/\
You find yourself inside a small room. In the corner, you see a sword, and decide to pick it up.
<<run $inventory.push('a sword')>>\
[[Continue|hallway]]You see a chest here in the hallway. \
<<if not $chestOpen>>\
Do you want to open it?
<<link [[Open the chest.|chest]]>>
/% concatenating the arrays and setting the result to $inventory moves all the items from the $chest array into the $inventory array %/
<<set $inventory to $inventory.concat($chest)>>
<<set $chestOpen to true>>
<</link>>
<<else>>\
It's open, and there's nothing inside.
<</if>>
[[Move on.|dart trap]]You open the chest and find <<= $chest.join(' and ')>>.
[[Okay.|previous()]]Several darts shoot out of a wall at you!
/% we can check to see if the player has a given item with Array#includes() %/
<<if $inventory.includes('a shield')>>\
Luckily, your shield will protect you.
<<else>>\
With no way to defend yourself, you die.
<</if>>