Allowing the player to define their own name in TADS2?

Hi all,

I’ve started tinkering on an experimental project, and I’ve looked through the documentation and can’t find how I would go about asking the player to input a name at the beginning of the game so they could be referred by it throughout.

Any tips would be most appreciated. Thank you :slight_smile:

Since TADS2 is pretty much dead, I’d strongly advise you to use its successor TADS3 (ideally with Eric Eves adv3lite-library). Because you just started your project, I see no reason why you should stick with v2.

I wasn’t going to say anything, but since plg brought it up – he’s right. T3 with adv3Lite is definitely the right choice. T2 is more than 10 years out of date.

A thread on rec.arts.int-fiction seems to cover this:

I’m new to TADS-2, but this code should work.
Code:
// First, a modification of the basicMe class.
modify class basicMe
fname = ‘’
lname = ‘’
name = “<<self.fname>> <<self.lname>>”
;

// Now, the askForName() function. You should call this in Init or commonInit.

askForName: function
{
while (true)
{
local up, low, yesno;
“\bWhat is your name?”;
up := upper(input());
low := lower(input());
if (up = nil or low = nil)
{ “\bPlease enter a first and last name.”; }
else {
“\nIs <> <> correct?\n”;
yesno := yorn();
if (yesno = 1)
{
parserGetMe().fname := up;
parserGetMe().lname := low;
addword(parserGetMe(), &noun, self.fname);
addword(parserGetMe(), &noun, self.lname);
}
else
{
askForName();
}
}
return;
}

I updated my rather buggy askForName code. It now requires parseword.t, by Kevin Forchione.
Here it is:

// First, a modification of the basicMe class.
modify class basicMe
fname = ''
lname = ''
name = "<<parserGetMe().fname>> <<parserGetMe().lname>>"
;

// Now, the askForName() function. You should call this in Init or commonInit.

askForName: function
{
while (true)
{
local wl, fn, ln, yesno;
"\bWhat is your name?";
wl := parseWord(input());
fn := wl[1];
ln := wl[2];

if (fn = '' or ln = '')
{ "\bPlease enter a first and last name."; }
else {
"\nIs <<fn>> <<ln>> correct?\n";
yesno := yorn();
if (yesno = 1)
{
parserGetMe().fname := fn;
parserGetMe().lname := ln;
addword(parserGetMe(), &noun, parserGetMe().fname);
addword(parserGetMe(), &noun, parserGetMe().lname);
}
else
{ 
askForName();
}
}
return;
}
}

It’s not dead. It still gets updates for any bugs that are found (which, at this point in time, are rather rare.) It’s new features that won’t be coming to it. But other than that, it’s fully supported.

1 Like