|
l33t3rth4nur1111 Newbie
Joined: 29 May 2005 Posts: 6
|
Posted: Sun May 29, 2005 10:28 pm
Making triggers out of state machines |
The "Advanced Triggers" document mentions how triggers using manual states can be used to implement state machines. However, it contains few details and no examples regarding this use.
For example, suppose I want to create a trigger that fires when the MUD sends text A, then takes one of two actions depending on whether text B or text C occurs next. A concrete example would be something like:
Let A be "You attempt to hide in the shadows."
Let B be "You fail"
Let C be "You succeed"
When A fires, then B, display "You feel like an idiot."
When A fires, then C, display "You fee like a ninja!"
Knowing how to do this would enable me to build larger, more useful state machines, but being new to zMUD scripting, I need simple examples.
So, how would I build such a trigger? |
|
|
|
Solaras Wanderer
Joined: 11 Mar 2002 Posts: 93
|
Posted: Sun May 29, 2005 10:39 pm |
This should work. It is how I reparse my own triggers for multiple states.
Code: |
#TRIGGER {You attempt to hide in the shadows.}
#COND {You fail.} {#ECHO You feel like an idiot.} {looplines|param=1}
#COND {You succeed.} {#ECHO You feel like a ninja!} {reparse}
|
|
|
|
|
l33t3rth4nur1111 Newbie
Joined: 29 May 2005 Posts: 6
|
Posted: Sun May 29, 2005 11:23 pm |
Hmm, guess my example wasn't the best. I was trying to come up with a simple example of a trigger using manual states as a state machine.
The procedure I'm going for is performing several actions on an object in sequence. Sometimes an action fails, and I have to perform it again. Other times the action fails so badly that I have to abort the entire procedure. I drew this out as a simple state machine with a short script for each state and a pattern for each transition. Now I'm attempting to convert it to an alias/trigger combo, but I don't understand the manual trigger mechanism enough to do so without at least one simple example.
[edit] Basically, I need execution to branch exclusively depending on which pattern is received after a state's scripted actions are performed. |
|
|
|
DeReP Adept
Joined: 14 Jun 2003 Posts: 222 Location: Chile
|
Posted: Sun May 29, 2005 11:29 pm |
What I use is temporary triggers to fire if a command fails
Ie:
#TRIGGER {You attempt to hide in the shadows.} {#TEMP "Hide_fail" {You fail.} {#You feel like an idiot.}}
#COND {You succeed.} {#ECHO You feel like a ninja;#T- Hide_fail} |
|
|
|
l33t3rth4nur1111 Newbie
Joined: 29 May 2005 Posts: 6
|
Posted: Mon May 30, 2005 2:53 am |
Okay, here's an example. Let's say I want to pick a lock repeatedly until it opens.
- hold lockpick. Possible response patterns are "You don't have a lockpick" and "You hold a lockpick." If the former, abort the trigger.
- pick lock. Possible response patterns are "fail" and "succeed". If the former, go back to step 2.
- stow lockpick.
This can be represented (among other ways) by a state machine with four states, one for each step plus a final state (state 4). State 1 transitions to state 4 on "You don't have a lockpick" and state 2 on "You hold a lockpick." State 2 transitions back to state 2 on "fail" and state 3 on "succeed". State 3 transitions to state 4 unconditionally. Modeling even this simple example as a multistate trigger is causing me no end of grief.
The reason I'm trying to use a multistate trigger is that the procedures I want to script are more complicated than the above one, and I don't want to have to resort to the old-style method of manually activating/deactivating separate triggers for each step. The "Advanced Triggers" document claims that I can do this with manual triggers, but I just don't see how. Could someone enlighten me as to how manual triggers can be used to model such a state machine? |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon May 30, 2005 3:14 am |
I would simply reduce the state trigger to two states and have a separate trigger for the succeed/fail part.
#oninput {hold lockpick} {#noop this is just an anchor point}
#cond {You ({hold|don't have}) a lockpick.} {#if (%1 = "hold") {pick lock}}
#trigger {({fail|succeed})} {#if (%1 = succeed) {stow lockpick}}
It's not a manual state machine, technically, but I bet it's a lot better than doing it that way. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Tarn GURU
Joined: 10 Oct 2000 Posts: 873 Location: USA
|
Posted: Mon May 30, 2005 4:32 pm Re: Making triggers out of state machines |
l33t3rth4nur1111 wrote: |
Knowing how to do this would enable me to build larger, more useful state machines, but being new to zMUD scripting, I need simple examples.
So, how would I build such a trigger? |
To implement a state machine, what you're probably looking for is expression triggers (not regular expression triggers, which makes searching the help hard).
There's a small example at
http://www.zuggsoft.com/library/trigadv.htm
under the Loop Expression section.
Basically, a command like
#trig (@somevar=0) {DoStuff}
will do DoStuff every time somevar is set from something else to 0.
You can have multiple states, and multiple ways to transition to each state.
If you don't define these via a command line, you'll have to use the second tab (States) of the trigger creation form to set the second column to Expression (defaults to Pattern for triggers created via "New").
Example:
#trig (@test=2) {#show test is two}
#trig (@test=3) {#show test is three}
Then, from the command line, assign values using #var test 2 etc. The assignment also works if it's in a trigger.
-Tarn |
|
|
|
|
|