Sample Code From Text-Adventure Game Platforms

I'm using the occasional snippet of spare time I don't have to write a 'platform' for constructing Wiki-based Adventure Games (more). It's a kind of -- and I shiver in horror at the term -- a Domain Specific Language.

So, when you're inventing a Domain Specific Language for writing Wiki-based Adventure Games... I guess it's a good idea to acknowledge:

a) You're gonna suck at it and

b) it's been done before.

So, I guess it's time to consult the classics.

Thanks to a post from _why, i've learnt about Scumm, the Script Creation Utility for Maniac Mansion.

Here's a snippet of ScummC provided by _why:

object carolObj {
name = "Indigenous lifeform";
verb(int vrb,int objA,int objB) {
case TalkTo:
zobTalkToCarol();
return;
case LookAt:
if( ! knowsCarol ) {
egoSay("A large carbon based mammal, it seems.");
waitForMessage();
}
else {
egoSay("It is Carol, one of the local lifeforms.");
waitForMessage();
}
return;
case Smell:
egoSay("This creature has an overwhelming pungent smell.");
return;
case Move:
egoSay("The lifeform is surprisingly sturdy, I don't believe I can use force.");
return;
}
}

Well that's very nice.

Sierra

Now, how about that megalith of adventure games from the 1980s, Sierra Online?

Sierra used an interpreter called AGI (adventure game interpreter) to make such classics as Leisure Suit Larry and King's Quest.

(Leisure Suit Larry is a kind-of formative game for my entire character and personality. In case you didn't realise this, I thought I'd spell it out now.)

Here's a code snippet:

if (said("look","door")) {
if (posn(ego,0,120,159,167)) {
print("These doors are strongly built
to keep out unwanted visitors.");
}
else {
print("You can't see them from
here.");
}
}

(example from: Making adventure games with AGI)

GrimE

GrimE is a game engine written in scripting language LUA, touted as "the successor to SCUMM, preserving some of that engine's features" (according to the big 'pedia.)

I haven't found a sample or a good starting resource -- so if you find one, please send it along.

Agast

Also under the wikipedia category of Adventure Game Engines, I found AGAST

Here's a morsel of agast scripting...

"For example, here's an event that is triggered when the player looks at his goldenmop:

event Lookat <> GoldenMop
{
EGO:
"It's my trusty golden mop."
"I got that years ago for saving the galaxy."
}

(later)

var TalkedToGiantLizard;

event Talkto -> GiantLizard
{
if TalkedToGiantLizard {
"Since he won't talk to me, I won't talk to him either."
}
else {
"Hi up there, Gozira!"
delay 10;
"He probably can't hear me, or he doesn't speak English."
TalkedToGiantLizard = true;
}
}

Wintermute

Wintermute (from dead-code) -- how awesome.

Here's an example of scripting for wintermute, (taken from here)

on "first"
{
Game.Msg("Do something after the first choice.");
}

on "second"
{
Game.Msg("Do something after the second choice.");
}

on "third"
{
Game.Msg("Do something after the third choice.");
dlgObject.removeIcon("second");
}

ZIL

Zil? Zork Implementation Language of course! What else would you implement Zork in?

And it's time for lisp-like languages to bring a close to this article ;-)

Here's what the definition of the Living Room from Zork I looks like:

<ROOM LIVING-ROOM
(LOC ROOMS)
(DESC "Living Room")
(EAST TO KITCHEN)
(WEST TO STRANGE-PASSAGE IF CYCLOPS-FLED ELSE
"The wooden door is nailed shut.")
(DOWN PER TRAP-DOOR-EXIT)
(ACTION LIVING ROOM-F)
(FLAGS RLANDBIT ONBIT SACREDBIT)
(GLOBAL STAIRS)
(THINGS <> NAILS NAILS-PSEUDO)>

(from 'Zil [pdf]')

(And how's this for an intriguing name for a pdf [from the ZIL entry at wikipedia] "How to Fit a Large Program Into a Small Machine")

Okay. That's about all I wanted to share. I think the similarities and differences are telling. You see common concepts like "ego" and character manipulation. You see different styles.

I'd like to make some pompous over-reaching statement that text adventure games encompass every deep complex issue of software engineering. That a platform that allows efficient construction of games would need to be a shining example of superb software craftsmanship, with all the right buzzword compliance to drag our industry into a new era of productivity.

But I think Douglas Crockford (inventor of Json) distills the soul of a great computer game, in his very entertaining article 'The Expurgation of Maniac Mansion, :

  1. meet people,
  2. kill people,
  3. take their money,
  4. buy more weapons.

And, indeed, This is the chief pattern I want to enable with my wiki adventure game. Mercenary. Ruthless. Vile. And most of all: good clean fun.

My head is sore. I must lie down now.

 

My book "Choose Your First Product" is available now.

It gives you 4 easy steps to find and validate a humble product idea.

Learn more.

(By the way, I read every comment and often respond.)

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.