Tutorial 7: Making a command usage monitor

Let's imagine you’re the owner of a Dream with lots of commands available, and so you would like to keep track of their usage statistics. To learn which ones are the most popular, you decide to keep track of how many times every command has been used.

Without the use of dynamic text substitution, you would have to create a single trigger for every possible command in your Dream, because each one has a different name than the other. But if we substitute the name of every PS entry with a special text replacement keyword, we can generate names that correspond to the current text held within that keyword. Here's how:




(0:0) When everything is starting up,

(5:212) set silent speech prefix (for spoken commands) to {@*}.

(0:32) When someone says something with {@*} in it,

(1:625) and the PhoenixSpeak info {[CMD]} about this Dream exists,

(5:612) remember the PhoenixSpeak info {[CMD]} about this Dream, and put it in variable %CMDStats.

(5:302) take variable %CMDStats and add 1 to it.

(5:602) memorize that the PhoenixSpeak info {[CMD]} about this Dream will now be %CMDStats.

(0:32) When someone says something with {@*} in it,

(1:626) and the PhoenixSpeak info {[CMD]} about this Dream does not exist,

(5:602) memorize that the PhoenixSpeak info {[CMD]} about this Dream will now be 1.

(0:32) When someone says something with {@*CMDStats } in it,

(1:625) and the PhoenixSpeak info {[PARAM1]} about this Dream exists,

(5:200) emit message {The command '[PARAM1]' has been used $dream.[PARAM1] times.} to the triggering furre.

Notice that every line that refers to a PS entry uses the special text replacement string called [CMD] instead of plain text. This is intended because when a variable, a string, a special text replacement string or even a PhoenixSpeak entry called through $ is used within any type of text {...} field, it is replaced by its value.

In this case, the silent speech of our Dream is set to @*, and the trigger assumes that anything that contains @* in it is a type of command. The name of the command is captured automatically with [CMD], allowing us to generate new PS entries that share a name with the command that was used, completely on the fly.

For example, if we were to use the following hypothetical command:

@*Entrance

Within our Dream, for the very first time, a PS entry named Entrance would be created within the Dream table of our Dream, with a value of 1.


Additionally, if we were to use the command once again, the trigger would only remember (load) the value of the Entrance entry, put it into a variable called %CMDStats, raise the number that the variable is currently set to by 1, and then memorize (save) the value of the Entrance entry to match the value of %CMDStats, which is now 2.

Account E-Mail

Password