Newsgroups: rec.arts.int-fiction
Subject: Re: [Tads question] Html for CYOA
From: gdighton@geocities.com (Garth Dighton)
References: <20010824095231.01455.00001188@mb-cq.aol.com>
User-Agent: Xnews/03.04.11
X-no-productlinks: yes
Message-ID: <3b869323$1_2@goliath2.newsgroups.com>
Date: 24 Aug 2001 12:47:15 -0500
Lines: 553
X-Authenticated-User: gdighton
X-Comments: This message was posted through Newsfeeds.com
X-Comments2: IMPORTANT: Newsfeeds.com does not condone, nor support,  spam or any illegal or copyrighted postings.
X-Comments3: IMPORTANT: Under NO circumstances will postings containing illegal or copyrighted material through this service be tolerated!!
X-Report: Please report illegal or inappropriate use to <abuse@newsfeeds.com> You may also use our online abuse reporting from: http://www.newsfeeds.com/abuseform.htm
X-Abuse-Info: Please be sure to forward a copy of ALL headers, INCLUDING the body (DO NOT SEND ATTACHMENTS)
Organization: Newsfeeds.com http://www.newsfeeds.com 73,000+ UNCENSORED Newsgroups.
Path: news.duke.edu!newsgate.duke.edu!nntp-out.monmouth.com!newspeer.monmouth.com!nntp.flash.net!newsfeed.wirehub.nl!local-out2.newsfeeds.com!goliath2.newsgroups.com
Xref: news.duke.edu rec.arts.int-fiction:91577

ddavemans@aol.com (Elcloud) wrote in
<20010824095231.01455.00001188@mb-cq.aol.com>:

>I was playing around with the 'choose your own adventure library for
>Tads' when i though 'wouldn't it be kool if i made all the choices
>links, so as to save people the trouble of typing 1, 2 etc.  So I tried
>implementing the Html and i managed to get the links working.
>Unfortunatly enabling Html screws up the statusLine and im unsure about
>how to make it the same as before.  Any suggestions or help would be
>most appreciated.
>

Here is a revision for HTML usage. Put the Place's name in placeName rather
than statusLine.

Example

startroom: Place
    	placeName = "West of House"
    	desc = "..."
    	choice...
;

The placeName will show up in a banner at the top of the game window
(standard for HTML games) I copied this from HTML-enabled adv.t.


/*---------------------------------------------------------------------
**
**
**
** File: CYOA_LIB
**
** Author: Mark J. Musante
**
** HTML revisions by Garth Dighton
**
** Revision History:
**
**  2001-Jul-05 GMD: Allowed HTML usage
**
**	1998-Feb-09	Added 'restart' command.
**
**	1998-Jan-25	Added 'save' and 'restore' commands.
**
**	1998-Jan-22	Added 'undo' command.
**
**	1998-Jan-20	Initial version.
**
**
**-------------------------------------------------------------------------
--*/

//
// These definitions are required by the compiler, but are not
// used in this game.
//
takeVerb: object;
strObj: object;
numObj: object;
againVerb: object;
pardon: object;


// "Me" is used by the runtime to determine the left-hand side
// of the status line. Whatever is in 'Me.location.statusLine'
// appears up there.
Me: object
	roomCheck( v ) = {
		return true;
	}
;

//
// Some global definitions.
//
global: object
	// ary is used by the choiceVerb class. Don't change it without
	// changing choiceVerb.action() as well
	ary = [ &choice_1, &choice_2, &choice_3,
	        &choice_4, &choice_5, &choice_6,
		&choice_7, &choice_8, &choice_9 ]

	// change death_msg before calling die(); if you want some
	// other message than 'You have died'
	death_msg = 'died'

	// if you want to change the propmt, change this
	prompt = '> '

	// this is the value that gets passed to initRestart when the user
	// requests a restart
	initRestartParam = 0


	// this is set to true in the default initRestart function
	restarting = nil
	lastPlace = nil
;

Place: object
	statusLine =    {
        /*
         *   Check the system to see if this is an HTML-enabled run-time.
         *   If so, generate an HTML-style banner; otherwise, generate an
         *   old-style banner.
         */
        if (systemInfo(__SYSINFO_SYSINFO) = true
            and systemInfo(__SYSINFO_HTML) = 1)
        {
            "<banner id=StatusLine height=previous border>
            <body bgcolor=statusbg text=statustext><b>";

            self.placeName;

            "</b></banner>";
        }
        else
        {
            self.placeName;
        }
    }

	placeName = "Wandering"
	desc = "* NO DESCRIPTION DEFINED *"
	choices = "* NO CHOICES DEFINED *"
	choice_1 = nil
	choice_2 = nil
	choice_3 = nil
	choice_4 = nil
	choice_5 = nil
	choice_6 = nil
	choice_7 = nil
	choice_8 = nil
	choice_9 = nil

	ConstructChoiceList = {}
;

DynamicPlace: Place
	choiceList = []
	choices = {say(self.chstr);}
	ConstructChoiceList = {
		local i, n;
		self.chstr := '';
		if (length(self.choiceList) > 0) {
			n := 1;
			// Construct the choice list, testing to see if each choice
			// is valid
			for (i := 1; i<=length(self.choiceList); i++) {
				if (length(self.choiceList[i]) < 3
					|| self.choiceList[i][3]) {
					self.(global.ary[n]) :=
self.(self.choiceList[i][2]);
					self.chstr := self.chstr + '\n\t(' + cvtstr(n) +
') ' +
						self.choiceList[i][1];
					n++;
				}
			}
			// Clear remaining choices
			for (; n<=9 ; n++) {
				self.(global.ary[n]) := nil;
			}
		} else {
			// Clear all choices
			self.chstr := "* NO CHOICES DEFINED *";
			for (i := 1; i <= 9; i++) {
				self.(global.ary[n]) := nil;
			}
		}
	}
;


/* 'modify' this object in your source code.
**
** Sample:
**	modify intro
**		desc = "Here's a really cool introduction to my game. "
**	;
*/
intro: object
	desc = "(*) CREATE AN OBJECT NAMED 'intro' AND GIVE IT A 'desc'
		PROPERTY. "
;

/* 'modify' this object in your source code
**
** Sample:
**	modify version
**		desc = "The Cool Game, Serial Number 050123, Release 6. ";
**	;
*/
version: object
	desc = "A Work of Fiction, created with TADS (the Text Adventure
		Development System) in conjunction with the CYOA_LIB by
		Mark J.\ Musante. "
;

/* 'modify' this object in your source code. This is the message that is
** displayed after the user decides to quit.
*/
endgame: object
	desc = "Thanks for playing!\b"
;

die: function
{
	local response;

	"\b\t* * * You have <<global.death_msg>>. * * *\b";

	while( 1 ) {
		"Would you like to (R)estart, Re(s)tore, (U)ndo, or (Q)uit? ";

		response := lower(input());
		if ( response = 's' || response = 'restore' ) {
			response := askfile( 'File to restore' );
			if ( response = nil )
				"Restore failed. ";
			else if ( restore( response ) )
				"Restore failed. ";
			else
				return;
		} else if ( response = 'r' || response = 'restart' ) {
			restart();
			return;
		} else if ( response = 'u' || response = 'undo' ) {
			if ( undo() ) {
				"(Undoing one command)\b";
				Me.location.desc;
				return;
			} else {
				"No undo information available. ";
			}
		} else {
			endgame.desc;
			quit();
		}
	}
}

//
// Here's where we give some basic advice.
//
parseError: function( err, str )
{
	if ( err = 2 )
		return 'I don\'t understand that command. For a list of ' +
			'valid comands, please type \'help\'.';
	else
		return nil;
}

//
// This function allows us to convert the command line into a word
// that the TADS parser will allow us to handle.
//
preparse: function( str )
{
	local foo;

	if ( str = '' ) {
		"Pardon me? ";
		return nil;
	}

	foo := cvtnum( str );
	switch( foo ) {
	case 1: return 'one';
	case 2: return 'two';
	case 3: return 'three';
	case 4: return 'four';
	case 5: return 'five';
	case 6: return 'six';
	case 7: return 'seven';
	case 8: return 'eight';
	case 9: return 'nine';
	default:
		if ( foo < 0 || foo > 9 || str = '0' ) {
			"Enter a choice from the menu, please. ";
			return nil;
		}
		return true;
	}
}

//
// only allow one entry per command line
//
preparseCmd: function( list )
{
	local foo := [];

	if ( length( list ) = 1 )
		return true;
	else {
		foo += list[ 1 ];
		return foo;
	}
}

//
// This is the startup code
//
init: function
{
	"\H+";

	"\b\b";
	intro.desc;
	"\b";
	version.desc;
	"\b";

	Me.location := startplace;

	Me.location.desc;
}

//
// Here's where we display the choice list & give the player the prompt
//
commandPrompt: function( type )
{
	if ( type = 0 || type = 1 ) {
		Me.location.ConstructChoiceList;
		"\bWhat would you like to do?\b";
		Me.location.choices;
		"\b";
		say( global.prompt );
	} else {
		">";
	}
}

//
// Basic choices.  Numbered 1 through 9.
//
choiceVerb: object
	num = 0
	action( actor ) = {
		local newloc;

		if ( self.num = 0 ) {
			"Parse error: number not set in verb.\n";
			abort;
		}

		if ( self.num < 1 || self.num > 9 ) {
			"Parse error: choice out of range.\b";
			abort;
		}

		if ( proptype( Me.location, global.ary[ self.num ] ) = 5 ) {
			"Please enter a choice from the menu. ";
			abort;
		}

		newloc := Me.location.( global.ary[ self.num ] );

		if ( newloc != nil ) {
			global.lastPlace := Me.location;
			Me.location := newloc;
			"\b";
			Me.location.desc;
		}
	}
;

oneVerb: choiceVerb
	verb = 'one'
	num = 1
;

twoVerb: choiceVerb
	verb = 'two'
	num = 2
;

threeVerb: choiceVerb
	verb = 'three'
	num = 3
;

fourVerb: choiceVerb
	verb = 'four'
	num = 4
;

fiveVerb: choiceVerb
	verb = 'five'
	num = 5
;

sixVerb: choiceVerb
	verb = 'six'
	num = 6
;

sevenVerb: choiceVerb
	verb = 'seven'
	num = 7
;

eightVerb: choiceVerb
	verb = 'eight'
	num = 8
;

nineVerb: choiceVerb
	verb = 'nine'
	num = 9
;

//
// Here's where the user can quit.
//
quitVerb: object
	verb = 'quit' 'q'
	action( actor ) = {
		local yn;
		"\bDo you really want to quit (YES or NO) > ";
		yn := yorn();
		"\b";
		if ( yn = 1 ) {
			endgame.desc;
			quit();
		} else {
			"Okay. ";
		}
	}
;

//
// Here's where the user can back up one turn
//
undoVerb: object
	verb = 'undo' 'u'
	action( actor ) = {
		if ( undo() && undo() ) {
			"(Undoing one command.)\b";
			Me.location.desc;
		} else {
			"No more undo information available.\b";
		}
	}
;

//
// This command is a concession to convention.
//
lookVerb: object
	verb = 'l' 'look'
	action( actor ) = {
		Me.location.desc;
	}
;

//
// Some very basic help
//
helpVerb: object
	verb = 'help'
	action( actor ) = {
		"This game does not accept standard interactive commands.
		Instead, it presents you with a situation and a number of
		choices to make. You can choose one of the options given,
		or you may enter one of the following:\n
		\thelp\tThis help message.\n
		\tquit\tEnd the game (abbr: 'q').\n
		\tlook\tRe-display the description of the situation (abbr:
'l').\n
		\tundo\tUndo the previous command (abbr: 'u').\n
		\tsave\tSave the current game in progress.\n
		\trestore\tRestore a previously saved game.\n
		\trestart\tRestart the game from the beginning.\n";
	}
;

//
// Save code paraphrased from adv.t
//
saveVerb: object
	verb = 'save'
	action( actor ) = {
		local savefile;

		savefile := askfile( 'File to save game in' );
		if ( savefile = nil or savefile = '' ) {
			"Failed. ";
		} else if ( save( savefile ) ) {
			"Saved failed. ";
		} else {
			"Saved. ";
		}
	}
;


//
// restore code paraphrased from adv.t
//
restoreVerb: object
	verb = 'load' 'restore'
	action( actor ) = {
		local savefile;

		savefile := askfile( 'File to restore game from' );
		if ( savefile = nil or savefile = '' ) {
			"Failed. ";
		} else if ( restore( savefile ) ) {
			"Restore failed. ";
		} else {
			"Restored.\b";
			Me.location.desc;
		}
	}
;

//
// restart code paraphrased from adv.t
//
initRestart: function( param )
{
	global.restarting := true;
}

restartVerb: object
	verb = 'restart'
	action( actor ) = {
		local yesno;
		while ( true ) {
			"Are you sure you want to start over? (YES or NO) > ";
			yesno := yorn();
			if ( yesno = 1 ) {
				"\b\b* * * RESTARTING * * *\b\b";
				restart(initRestart, global.initRestartParam);
				break;
			} else if ( yesno = 0 ) {
				"\nOkay.\n";
				break;
			}
		}
	}
;


-----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
 Check out our new Unlimited Server. No Download or Time Limits!
-----==  Over 80,000 Newsgroups - 19 Different Servers!  ==-----
