[TADS 2] Creating a 'bug' command for the transcript

(This question is inspired by this Jolt Country thread, btw).

Is it possible to do this in TADS 2? If so, what built-in functions (parseUnknownVerb(), etc.) should I look into?

There are several ways to arrange it in TADS 2, but the easiest one probably is using the preparse function. It’s automatically called at the very beginning of the parsing process, with a single argument of the string type that actually represents the command entered by the player. The preparse function may return one of the following values:

nil - in this case, the system assumes all the processing has been done by preparse, and skips to the command prompt without any further processing;
true - the system resumes processing the original player input normally;
string value - the system resumes parsing, using the returned string value instead of the original command entered by the player.

More on it see here (use text search by the name of the function).

To recognize a command with an asterisk at the beginning as a comment, the preparse function could be set up like this:

preparse: function(str)
{local i, symb;
 if(length(str)<=0) // Default processing for empty input 
   {return true;
   }
// Initializing the loop to find the asterisk
 i:=1;
 symb:=substr(str, i, 1);
 while((symb=' ') and (i<length(str))) // We're skipping leading spaces
   {i++;
    symb:=substr(str, i, 1);
   }
 if(symb='*') // This is a comment
   {"COMMENT RECORDED";
    return nil; // No further processing needed - return nil
   }
 return true; // It wasn't a comment - process the command normally
}

Note that it’s a little bit more sophisticated - it doesn’t just check the first symbol of the player input, but also skips the leading spaces. If such behaviour is unwanted, just erase the entire while loop.

Thanks, uux02! I had initially drafted something like this before, using find() instead of substr(), and without stripping the leading spaces. It looks like this part is where I got confused when I tried to write it on my own:

as well as:

if(symb='*') // This is a comment {"COMMENT RECORDED"; return nil; // No further processing needed - return nil } return true; // It wasn't a comment - process the command normallyI should have returned nil after recognizing the ‘’ (I kept getting "I don’t understand the punctuation '’" errors before) and returned true instead of the actual command string at the end. Sheesh :unamused:

Thanks again!