game.title = "Demo game"; game.author = "Mike Buland"; game.version = 1; game.revision = 0; game.start = <>; global { /** * This is an example of a very general "travelling" command. It inspects * the current situation to see what exits are available, and if the given * exit is in the situation.exits dictionary it goes that way. */ command: "go" dir { if exists(situation.exits) then { if dir in situation.exits then { goto( situation.exits[dir] ); } } display('''You're not really sure how to do that...'''); } /** * A simple command that lists the currently visible exits. */ command: "exits" { if exists(situation.exits) then { display( "Obvious exits are: " + join( keys( situation.exits ), ", " ) ); } else { display("There are no obvious exits."); } } /** * Takes an item from the current situation, if it's there, and adds it to * the user's inventory. */ command: "take" item { if exists(situation.items) then { if item in situation.items then { situation.items -= item; player.inventory += item; display("You take the " + item); return(); } } display("You don't see that anywhere."); } /** * Lists items that are in the user's inventory. */ command: "inventory" { out = 'You are carrying: ' + join( player.inventory, ", " ); display( out ); } // You should always have a global exit, quit, escape, something for // dev-testing at least. command: "quit" { exit(); } } situation <> { setup { player.inventory = []; display('''You awaken after a long, dreamless sleep to find yourself lying on a hard, cold, deserted beach. You have no memory of how you got here. After a few minutes your eyes adjust to the bright, glinting daylight shinning off the crests of the waves in the ocean. You don't seem to have anything with you but the clothes you're wearing. (You also posses an eerily accurate innate sense of direction.)'''); } enter { goto( <> ); } } situation <> { /** * This overrides the global go command for the east parameter. */ command: "go" "east" { display("Those rocks are far too sharp and jagged, you don't think you could make it over them."); } setup { situation.exits = { 'west': <> }; } enter { display('''You're standing on a narrow stretch of beach. The ocean sparkles to the north, there's a cliff face just to the south. The beach extends [green>westward> { setup { situation.exits = { 'east': <>, 'west': <> }; situation.items = ['stick']; } enter { } } situation <> { setup { situation.exits = { 'east': <> }; } enter { } }