Is user input possible?

I am extremely new to TADS 3 and I would like to know if there is a way to convert user input to a variable. For example; in the test game I’m creating I have a guard at a restringing counter asking the player character what their name is. What I want to do is have their name to be used throughout the rest of the game in conversations. Such as “Nice to see you (x).” I can’t find it anywhere in the manual or online.

I’m assuming you are using the default adv3 library, not Eric Eve’s alternate adv3Lite library.

Try this, at the place in your code where you want to capture the input:

/* Ask for input and store it in a variable. */
local responseText = readMainCommand(rmcCommand);

That may be all you need. The rmcCommand parameter makes the input routine believe you are asking for a regular command, but that won’t make a difference here.

A slightly more elaborate version (which might actually be good style) would show a different input prompt for the purpose of asking for the player’s name, informing the player that normal command parsing doesn’t apply. This would go as follows:

First, somewhere in your code in a place appropriate for static definitions, add this:

/* Define a new input prompt type. */
enum rmcName;

modify libMessages

mainCommandPrompt(which)
{
    /* When asking for a name, display a >> prompt. */
    if (which == rmcName) "\b&gt>";
    /* Otherwise, display the regular prompt. */
    else inherited(which);
}

;

And then, at the place where you want to ask for a name:

/* Ask for input, telling the input routine to display the proper prompt for a name. */
local responseText = readMainCommand(rmcName);

Would I put it where I’ve listed the NPC that asks for the name or would it be its own separate code? I also keep getting this errror;
“A property name was expected in the object definition, but the compiler found
“local” instead. Check for a missing semicolon at the end of the object
definition, and check for unbalanced braces prior to this line.”

The error you’re seeing seems to imply that you have put the code inside of an object definition (possibly the NPC object), but not inside any function of method, which is where “local” would be meaningful.

You have to put that code fragment in the part of the code that’s executed when the NPC asks for your name - the code that describes what happens then - as opposed to the declarative part of the code that defines the static, intemporal features of the NPC itself. Otherwise, apart from the compilation error you’re seeing, the game would have no way to know exactly when the player’s name should be asked for.

Since I don’t know what that code looks like in your game, I can’t be more precise, but I can give an example of where to put things if the player’s name were to be asked for at the beginning of the game:

gameMain: GameMainDef
initialPlayerChar = me

showIntro()
{
    "Please input your name. ";
    local responseText = readMainCommand(rmcName);
    "Greetings, <<responseText>>.<.p> ";
}

;

Note that it’s now inside a method, showIntro(). This means this code is meant to execute at a particular moment (in this case, when the game begins), not to describe how things permanently or initially are.

In contrast, the special modal prompt (if you want it) is a static feature of the game, and should be defined at top level, outside of any object:

/* Define a new input prompt type. */
enum rmcName;

modify libMessages

mainCommandPrompt(which)
{
    /* When asking for a name, display a >> prompt. */
    if (which == rmcName) "\b&gt&gt;";
    /* Otherwise, display the regular prompt. */
    else inherited(which);
}

;

I apologize but I’m still incredibly confused. If it helps this is my code for the NPC I want to ask for the name.
guard: Person ‘Vault-Tec Guard/Employee’ ‘Vault-Tec Employee’ @thirdRoom
“There is a man holding a Vault-Tec brand clipboard and wearing a Vault-Tec Employee outfit.”
isHim = true
cannotKissActorMsg = ‘This is not the time to randomly kiss a guard. Maybe later though’
cannotEatMsg = ‘You can't eat the guard. Not with so many witnesses’
unlessToAttackMsg = ‘No attacking the help. At least with not with so many witnesses.’
guard: Person ‘Vault-Tec Guard/Employee’ ‘Vault-Tec Employee’ @thirdRoom
“There is a man holding a Vault-Tec brand clipboard and wearing a Vault-Tec Employee outfit.”
isHim = true
cannotKissActorMsg = ‘This is not the time to randomly kiss a guard. Maybe later though’
cannotEatMsg = ‘You can't eat the guard. Not with so many witnesses’
unlessToAttackMsg = ‘No attacking the help. At least with not with so many witnesses.’
Intro()
{
"‘Name’ he says in an almost bored tone. As if the world wasn’t ending on the surface above. ";
local responseText = readMainCommand(guard);
“‘Alright, <>.<.p> ,move forward’ he hands you a jumpsuit and a manual that read ‘Vault Life’ on the front.”;
}
;

It seems to me that the first thing to get clarity about is: when exactly do you want the guard to ask for the player’s name? Is it when we enter thirdRoom for the first time? Is it when the player says hello?

Ignoring for a moment the issue of asking for player input, and pretending that the player character has a name that’s predefined in your story, independent of any user input: how would you implement things to have the game report the conversation between the guard asking for the PC’s name and the PC responding with their predefined name? That may be a whole question to solve in its own right, but one that’s worth figuring out in the first place.

What I was getting at is, once you have implemented the conversation between the PC and the guard assuming a predefined name, then the place to insert the code to ask for user input is probably right after the guard’s line of conversation - but the conversation has to be implemented somewhere, user input or not.

I want the guard to ask the PC when the PC examines him and the guard asks for the PC’s name.
Where I want to implement the name for the first time is after the PC tells the guard his name. He’ll mumble it, write it down, and tell the PC to move on. I want the name to be user input to increase the level of role-within the game. I think that’s what your asking for.

It sounds like what you’re struggling with is the creation of a side effect of carrying out some action (in your case, examining the guard).

One way to do it would be as follows:

guard: Person 'Vault-Tec Guard/Employee' 'Vault-Tec Employee' @thirdRoom

    // Other definition elements come here

    dobjFor(Examine)
    {
        /*  Define a side effect to examining the guard.  */
        action()
        {
            /* Carry out the normal Examine implementation: show the description */
            inherited();
            /* Ask for the PC's name if not known already. */
            askForPcNameIfNotKnown();
        }
    }

    /* Ask for the PC's name if not known already. */
    askForPcNameIfNotKnown() {
        if (knownPcName != nil)
        {
            /*  The PC's name is known already - do nothing and return immediately. */
            return;
        }

        /*  Ask for the PC's name.  */
        "'Name' he says in an almost bored tone. As if the world wasn't ending on the surface above. ";
        knownPcName = readMainCommand(rmcCommand);
        "'Alright, <<knownPcName >>.<.p> ,move forward' he hands you a jumpsuit and a manual that read 'Vault Life' on the front.";
        
    }

    /*  Initially the guard doesn't know the PC's name.  */
    knownPcName = nil;
;

/* Define a new input prompt type. */
enum rmcName;

modify libMessages

    mainCommandPrompt(which)
    {
        /* When asking for a name, display a >> prompt. */
        if (which == rmcName) "\b&gt&gt;";
        /* Otherwise, display the regular prompt. */
        else inherited(which);
    }
;

(In case you’re wondering why my previous examples used “local” in front of the response text variable and this one does not: local defines a local variable, one that exists only until the end of the { }-delimited block where it’s defined. In this more complete example, the response text is stored in a property of the guard, which exists indefinitely.)

If you later want to define other triggers for the guard to ask for the PC’s name (say, when the player says hello), you can call the guard’s askForPcNameIfNotKnown() method in those other circumstances.

I don’t know if this example makes the general idea clear enough for you to apply or extend it to other cases where you may want to trigger the side effect of the guard asking for the name, or to do something similar but different if you want to… If not, I’d recommend having a closer look at how this action processing works in Eric Eve’s tutorial Getting Started in TADS 3, Chapter 4, Section “Controlling the Action” (for action side-effects), in particular the action() and afterAction() handlers. Possibly also Chapter 5, Section “The Art of Conversation”, to get a feel of how conversations work, in case at some point you want also to try having the guard ask for the PC’s name after the player says hello.