Online Role Playing Games: Coding for the True Newbie - Teaching Troubling Triggering, vol. 2
By Rio Rivera-Young
Ah, triggers. The subject of a great many a debate starting back in Aristotle’s day. Ok, maybe not that far back; however, these not-so-hot-topic reflexes were actually an issue once upon a time. Often banned in many MUDs, triggers were undesirable due to fears of automation and cheating. Nowadays, however, a good grasp of triggers are nearly required to play most online text games due to the excellent fast-paced nature of game-play. So, let’s walk you through the basics of triggers, and then continue on our previous example of targeting that we covered before.
In case you missed my previous tutorial on simple coding, a trigger is “an automatic, coded reaction to a certain pattern of text.” If you need a good real life analogy, I recommend you check out volume 1 here.
Now, there are many facets to a trigger, we’ll start with a pattern. A pattern is the most essential piece of a trigger – for it is easy to make a trigger which does nothing, but it’s quite complicated to make a reaction to no stimulus. There are two types of patterns that we’ll cover pertinent to Achaea – simple patterns and complex patterns. The other facet is the reaction; however, that’s a significantly easier topic, so we will cover it later in the tutorial.
A simple pattern is a pattern that will appear the same way every time. For this example, let’s say that you have a mother who bought you an obscenely bad Christmas sweater. Every time you see this sweater, you frown. That’s a simple pattern – a reaction to a specific instance.
Now, there are such things as complex patterns as well. To talk about a complex pattern, we have to introduce and define the subjects of wildcards. A wildcard is something which can substitute for many things. For a real life example, let’s say meat is a wildcard. Now, if you say you don’t eat meat, there are many things it can match. Pork is a meat, as is poultry, beef, venison, and so on. A complex pattern is a pattern that contains wildcards in addition to known text, although there are ways to make triggers solely out of wildcards!
Another related subject is the “escape” character. When we are capturing something, we put parenthesis around them. What if we want to trigger something with a parenthesis in it?! We “escape” it. In mudlet, this is accomplished with a forward slash “\”. In z/cmud, you use a tilde “~”. We’ll cover this in the specific trigger below!
Now, the magical world of wildcards can get quite complicated, and there will be an article devoted to regular expression (the common way of capturing wildcards), but for now, all that it’s necessary to know is what wildcard captures which thing. The individual elements come later! We’ll start with Mudlet. In Mudlet, to capture a number use “(\d+)” without the parentheses, of course. Think “digit” instead of number to memorize it. This can capture multiple digits, as well as single ones, so feel free to use it whether the number might be 2 or 20000. To capture a word, use “(\w+)”. To capture a space or a group of spaces, use “(\s+)”. In Z/Cmud, these change slightly. (%d) is how you capture a digit, (%w) is how you capture a word, and (%s) is for capturing multiple spaces.
Now, let’s put this information to use! We’re going to use variables from the previous articles, so if you don’t understand where something comes from, it’d be a good idea to check it out! In Achaea, it’s popular to change targets based on what others are targeting, so oftentimes they will be called over a party channel. It’s easy to miss target calls, however, so we’re going to make a trigger to do it for us!
Now, here is our example.
(Party): Neraeos says, "Target: Tecton."
That’s right ladies and gentlemen, it is finally time. The God of the Sea has finally decided to usurp the Terraformer, and you’re on Team Waterworld. It’s gonna be some fast-paced fighting, so let’s get this trigger working. First, let’s figure out what all we need to escape. To be safe and sound, we’re going to escape any symbol that may appear in the pattern.
So, now our pattern looks like this in Mudlet:
\(Party\)\: Neraeos says\, \"Target\: Tecton\.\"
and in Z/CMUD
~(Party~)~: Neraeos says~, ~"Target~: Tecton~.~"
Now, that’s all well and good, but we don’t need a trigger to tell us to target Tecton, we need one that changes our target to whatever Neraeos decides! So, as we covered before, we’ll use a wildcard. We want the wildcard to stand for our target, so let’s replace Tecton with (\w+), or (%w) in Z/CMUD, as it’s a word we’re replacing.
\(Party\)\: Neraeos says\, \"Target\: (\w+)\.\"
~(Party~)~: Neraeos says~, ~"Target~: (%w)~.~"
Alright, we have our pattern all set up, but now it comes to the problem of how to use it! Sure, we have our nifty little wildcard, but how does that help us change the target variable to match what it matches? In Mudlet, this is accomplished with “matches”. A little complexity is that to match the first wildcard, we need to use matches instead of matches. So, for our reaction, we will put “target = matches” to set the targeting variable we created last time to the matched wildcard. In Z/CMUD, this is accomplished differently. To match a wildcard in these clients, we use “%”, where the number corresponds to the number of the wildcard used. In this cast, as we are trying to match the first wildcard, we will put “#VAR target $1” as our reaction. And voila! Now our target will change with the Sea Lord’s whim, and we can use the kill alias provided in the last tutorial to give the Terraformer hell!
I hope you enjoyed and learned from this tutorial, and be prepared! Next time, we delve into the magical world of if statements.
Try some targeting for yourself in some great text-based RPGs.
Rio Rivera-Young is a text game enthusiast and currently plays games from http://www.IronRealms.com.