[TADS3] Parsing Strings

Dear all,
I would like to have a “goto” verb that accepts strings, and I would like to parse those strings. Purpose is to move the player to certain rooms. Like, “goto bathroom”, “goto courtyard”, “goto living room” etc. How do I do this? I started with

DefineTAction(Goto);
VerbRule(Goto) ('goto') singleTopic : GotoAction
    verbPhrase = 'goto/going (what)'
;

but what’s next?
Thanks and kind regards,
Grues

1 Like

I’m assuming you want to replace singleTopic with singleDobj and make sure to include vocabulary for the Room objects you want to be able to go to. But if you’re using adv3Lite, there should be a built-in go-to (pathfinding) verb: have you looked at that?

2 Likes

I’m using TADS 3. I am aware this “lite” thing exists but I don’t know what it is.

In Inform 6 my code would look like this:

[ Verb_GotoSub wd;
	wn = consult_from;
  	wd = NextWord();
  	if(wd=='beach') {playerto(Room015); rtrue;}
  	...
  	if(wd=='lounge') {playerto(Room024); rtrue;}
	"Unknown destination.";
		];

I would like to do the same in TADS 3. Thanks!

You can use adv3Lite with TADS 3. From what you say, I imagine you’re using the adv3 library. Adv3Lite is an alternative library, which you could use instead. As John says, it already implements a GOTO command, so you wouldn’t need to devise your own. On the other hand, if you’re already some way into your current TADS3/adv3 project you probably wouldn’t want to change libraries at this point.

If you want to implement a GOTO command in adv3 you’ll probably want to use the pathfind.t extension that comes bunded with TADS 3.

2 Likes

Thank you, thank you both, but please, I want to learn how to parse text instead of objects. Right now it’s “goto X”, later on it’ll be “type Y”. If there’s any documentation on this matter, that’d probably already be helpful. The “Learning TADS 3” unfortunately didn’t help me; I assume chapter “7.3 Topics” could be helpful but I don’t understand how to apply topics when parsing a verb. Sorry for the inconvenience.

The ‘How to Create Verbs in TADS 3’ article explains what you want to do in the section ‘Verbs with a “literal” object’.

https://www.tads.org/howto/t3verb.htm

I believe the code would look something like this:

DefineLiteralAction(Goto)
     execAction()
     {
         local dest = getLiteral();
         if(dest == 'beach')
             gActor.moveInto(beach);
         else if(dest == 'lounge')
             gActor.moveInto(lounge);
         else
             "Unknown destination. ";
     }
 ;
 
 VerbRule(Goto)
     'goto' singleLiteral
     : GotoAction
      verbPhrase = 'go/going (where)'
 ;
1 Like

Works like a charm, and it’s applicable for other purposes. Thanks a lot!!!

1 Like

I’m glad that worked for you, but did you take a look at JZ and Eric’s advice(s)? As your game gets geographically large, you are going to have to maintain an ever-growing list of rooms to decode. Heaven forbid you also need to distinguish between ‘white room,’ ‘dark room,’ waiting room’ and an exploding synonym mix. Additionally, if you need to keep track of ‘wait, a locked gate is between player and foyer’ you will quickly find yourself reimplementing lots of things TADS (adv3, adv3lite) is already doing for you.

If it were me, I’d look at pathfinder.t rather than trip over that kind of stuff.

Less helpful in the >TYPE ‘XXX’ case, granted, but maybe you are not having to match all possible strings in that case?

2 Likes

Hi JJ, I was not looking for pathfinding actually, but for a way to jump to certain places that allows for synonyms, And for the way to parse text. :wink: Cheers!

1 Like

I’m fooling around the idea of a “fast GO TO” for a3Lite (basically is a superbrief.go to [loc].verbose which reduces the spewing of long loc description in more or less bad english… the rationale being that going to a loc is a fast walking/trotting towards the destination without much looking around (of course, if major things happens (major = catch the PC’s attention) during the fast walking, the GO TO is interrupted; this is where lies the difficulty of implementation, but is still on the drawing table, but if I successfully code it, I’ll duly share the code :wink:

Best regards from Italy,
dott. Piergiorgio.

1 Like

@Piergiorgio_d_errico
You can pretty much get that effect already if you set gameMain.fastGoto to true and the player uses the BRIEF command before issuing a GO TO command, but I’ll look into adding another gameMain option (briefGoTo, perhaps) that automates this. It may turn out to be quite simple to do, and will avoid your having to reinvent a number of wheels.

EDIT: I’ve now pretty much got the proposed gameMain.briefGoTo option working. It may need a little more tweaking but I’m nearly in a position to add it to the next release of adv3Lite.

2 Likes

Thanks, Eric ! with this I can concentrate on the possible exceptions !

Best regards from Italy,
dott. Piergiorgio.