Running a function before command runs

I would like to run a function anytime the player enters a command or verb. Either through the#inputTextCommand or by clicking a #verbButton in the #gamepanes.

Can you think of a way to do this without adding the function to every command?


You could override the function HandleSingleCommand?

That's called after the game has determined which command the player entered, but before checking the objects mentioned in the command against the available objects.

The default function is:

  <function name="HandleSingleCommandPattern" parameters="command, thiscommand, varlist">
    // current command string
    game.pov.currentcommand = command
   
    // current command object
    game.pov.currentcommandpattern = thiscommand
   
    // string dictionary of variables, e.g. object1="book"; object2="table"
    game.pov.currentcommandvarlist = varlist
   
    // string list of variables left to resolve
    game.pov.currentcommandvarlistqueue = NewStringList()
    foreach (key, varlist) {
      list add (game.pov.currentcommandvarlistqueue, key)
    }

    // dictionary of resolved elements, e.g. object1=book_object; object2=table_object
    game.pov.currentcommandresolvedelements = NewDictionary()

    // list of resolved elements, e.g. book_object; table_object
    game.pov.currentcommandresolvedobjects = NewObjectList()

    game.pov.currentcommandunresolvedobject = null
    game.pov.currentcommandpendingvariable = null
    ResolveNextName
  </function>

You could add your own line to that function, to run whichever script you want.
If you want to know whether the player typed a command or clicked a link, you could look at game.pov.commandmetadata. If the player clicked a command link or a verb button, then this will be a string dictionary in which the key is the alias of the selected object (as it appears in the command string), and the value is the object's name.

If you're doing this a lot, it might even be possible to modify a couple of functions to make a new kind of turnscript, that runs before the command is executed. Might be a bit tricky to work with, though.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums