Event Chains

version 1 by William S Martin

  • Home page
  • Beginning
  • Previous
  • Next



  • Section: How it works

    Event chains provide a phrase that moves down a table, stopping when it meets the first row it can access. Here's a breakdown:

    1) Starting from top, it looks for a non-blank table row,

    2) When it finds one, it looks to see if there's a checker entry, which is a rule that tests for conditions.
    --if it doesn't have a checker entry, it stops there, follows the rule in the toggle entry, says the reply entry, and then blanks out the entire row.
    --if it does, it tests the checker entry, moving to step 3.

    3) The event chain checks the checker entry.
    --if the checker rule succeeds, it moves to step 5.
    --if there is no outcome, it moves onto the next entry without blanking out the row.
    --if the rule fails, the event chain stops, following step 4.

    4) This step should only be considered when the check rule failed. When that happens, chain stops on that row, follows the toggle rule and says the reply entry, if there is one or both.

    5) This step is considered when the check rule succeeds, or if there is no checker rule. The chain stops on this row, follows the toggle rule, says the reply entry, then blanks the row out, never following it again.

    Using this system, the examples above would look something like this:

    *:
        After talking to Hugh:
            step through chain Table of Hugh Conversation.
        
        Table of Hugh Conversation
      checker  toggle  reply  
      chk001 rule  --  "'Sir, I need your luggage.'"  
      --  tg001 rule  "'Thank you sir,' he says, taking your luggage."  
      --  --  "'Thank you sir.'"  
      --  --  "'Thank you sir.'"  
      --  --  "'Thank you sir.'"  
      --  --  "'Thank you sir.'"  
      --  tg002 rule  "In a fit of rage, Hugh punches you in the face."  
      --  --  "'Thank you sir'"  
        
        Checker rule (this is the chk001 rule):
            if the player is carrying the luggage:
                rule succeeds;
            else:
                rule fails.
        
        Toggle rule (this is the tg001 rule):
            now Hugh is carrying the luggage.
        
        Toggle rule (this is the tg002 rule):
            now the player is bruised.

    This is functionally identical to the other two examples aboves, except 1) it functions using only one After rule, decreasing the chance of a conflict with other rules, or things happening in the order that you don't want them to occur, and 2) it doesn't require the use of a counter.

    One caveat: an Event Chain will never delete the last row of a table, unless you use the "terminating" phrase option, which can delete the last row. So saying:

        step through chain Table of Hugh Conversation, terminating

    will cause the Event Chain to delete even the last row if the Checker rule doesn't fail.

    Whether Event Chains is useful is entirely subjective. Personally, I feel as though Event Chains has helped my code get cleaner, is less likely to have a bug and much more likely to do things in the order that I want them done, but that is entirely my experience alone. Event Chains in different situations can be more work, and it isn't designed to be a total replacement for the rule-based system. While you could, theoretically, run an entire action using an event chain alone by use a STEP THROUGH CHAIN phrase during a CHECK rule, it isn't recommended.

    The checker and toggle rulebooks are purely to organize rules. You should never run through the rulebook, as in ABIDE BY THE CHECKER RULES.