Magic Words - TADS3.1

I have reached a point in my story where I want to start using ‘magic words’. They will mostly be intransitive verbs that will be ‘magic word’ commands that will enable direct travel or other actions. I would also like these verb groups to be able to handle conditional parts that use conditional things such as ‘if-if else-else’ and so forth. These will be one set
of the heavily used comands of the story. I’m looking for source code examples or other ideas on how I might go about this. Any ideas or help is more than welcome. Thanks, in advance.

RonG

The code for any given “magic word” (especially intransitive ones) is going to be more or less the same as the code for the Glow action that we’ve worked on in the past.

See: https://intfiction.org/t/go-to-the-light-tads3-1/3688/1

In generic form, it will look like this:

DefineIAction(MAGICWORD)
	execAction() {
		// action code goes here
	}
;

VerbRule(MAGICWORD)
	'MAGICWORD'
	: MAGICWORDAction
	VerbPhrase='MAGICWORD/MAGICWORDing'
;

Where you replace all instances of MAGICWORD with some new word.

I’ve enclosed some VERY rough code which is my first attempt at using a ‘magic word’ My problem is that I’m not very sure as how to set up the punctuation and structure of this code. I could use some help with this.

RonG

/*******************************************************************************
*  Magic Words - To create an intransitive verb (no object), you have to write *
*  at leasr two sections of code.                                              *
*******************************************************************************/

/*  Melenkurion - Magic Word - Is Travel Action  ******************************/

VerbRule(Melenkurion)
   'Melenkurian'
   : MelenkurionAction
   verbPhrase = 'Melenkurion'
;

DefineIAction(Melenkurion)
   execAction(){
      //action code goes here
      if me !in Room1
         "That word, although quite powerful, won't work here. Try another
          location. "
         break
      else
         goto Room3
   }
;

Your verb is “Melenkurion” but the triggering word in the VerbRule is “Melenkurian” - that seems to be a mistake.

You aren’t following the language syntax rules in your execAction method. You can try this:

DefineIAction(Melenkurion)
   execAction(){
      //action code goes here
      if (gPlayerChar.getOutermostRoom != Room1) {
          "That word, although quite powerful, won't work here. Try another
           location. "
      }
      else {
          gPlayerChar.moveIntoForTravel(Room3);
          gPlayerChar.lookAround(true);
      }
   }
;

Your code works perfectly. I’ll be able to alter it for many uses. Thanks for all the quick responses that you give.

RonG