Title: Windows Live Agents: Context Zones
Slug: windows-live-agents-context-zones
Date: 2008-09-01 11:29:00
Author: Kartones
Lang: en
Tags: Development, Windows Live Agents, Testing
Description: Creating context zones with Buddyscript.

 <p align="justify"><span style="line-height: 1.428571429;">With Buddyscript, you can define </span><b style="line-height: 1.428571429;">context zones</b><span style="line-height: 1.428571429;">, that restrict processing of patterns based on a simple condition. We're going to talk about some "advanced" tricks you can do.</span></p> <p>Usually, we will use context zones with flag variables, in order to activate or deactivate them. <br>But one point not mentioned in the documentation is that you can nest them, or even have them in different files. I will show you an example.</p> <p>First, define this two variables and context subsections somewhere in your code (for example in a global variables file):</p> <p><font face="Courier New">variable G_MAIN_SECTION = 0<br>context MainSection {condition="G_MAIN_SECTION==1" out-of-context="0"} </font> </p><p><font face="Courier New">variable G_SUB_SECTION = 0<br>context SubSection {condition="G_SUB_SECTION==1" in-context="110" out-of-context="0"}</font>  </p><p> </p> <p>Then, place this code in one separate file:</p> <p><font face="Courier New">begin context MainSection </font> </p><p><font face="Courier New">+ test_split_section {score=900}<br>  - You're in the main context section, split file </font> </p><p><font face="Courier New">begin context SubSection </font> </p><p><font face="Courier New">+ test_split_section {score=900}<br>  - You're in the sub-context section, split file </font> </p><p><font face="Courier New">end context SubSection </font> </p><p><font face="Courier New">end context MainSection</font>  </p><p> </p> <p>We define a pattern (<font face="Courier New">test_split_section</font>) that will only be triggered if we're on the <font face="Courier New">MainSection</font> context, and another one with the same name that will only be triggered if we're both in the main and the <font face="Courier New">SubSection</font> contexts. So, we will get different outputs if we've entered one or both contexts ;)</p> <p> </p> <p>Finally, put the following code in another separate file:</p> <p><font face="Courier New">+ start<br>  - Entering main section<br>  G_MAIN_SECTION = 1 </font> </p><p><font face="Courier New">+ test_section<br>  - You're out of the main section </font> </p><p><font face="Courier New">begin context MainSection </font> </p><p><font face="Courier New">+ test_section {score=900}<br>  - You're on the main section </font> </p><p><font face="Courier New">+ abandon {score=900}<br>  - Going out of the main section<br>  G_MAIN_SECTION = 0 </font> </p><p><font face="Courier New">+ start {score=900}<br>  - Entering sub-section<br>  G_SUB_SECTION = 1 </font> </p><p><font face="Courier New">begin context SubSection </font> </p><p><font face="Courier New">+ test_section {score=900}<br>  - You're on the sub-section </font> </p><p><font face="Courier New">+ abandon {score=900}<br>  - Going out of the sub-section<br>  G_SUB_SECTION = 0 </font> </p><p><font face="Courier New">end context SubSection </font> </p><p><font face="Courier New">end context MainSection</font>  </p><p> </p> <p>So, we have re-definitions of three patterns:<br></p> <ul> <li><font face="Courier New">start</font>: Enters the main section, or if we're inside it, enters the sub-section  </li><li><font face="Courier New">abandon</font>: Exits the main section, or if we're inside the sub-section, exits the sub-section (if we're not on either section, it doesn't works)  </li><li><font face="Courier New">test_section</font>: Tells us where we are</li></ul> <p>Now, here is a sample question/response output showing how all the code works. Notice how being in subsections and calling <font face="Courier New">test_split_section</font> works too!</p> <p> </p> <p><font face="Courier New"><font color="#004080">&gt; test_section</font><br><font color="#800000">&lt; You're out of the main section<br></font><font color="#004080">&gt; start</font><br><font color="#800000">&lt; Entering main section</font><br><font color="#004080">&gt; test_section</font><br><font color="#800000">&lt; You're on the main section</font><br><font color="#004080">&gt; test_split_section</font><br><font color="#800000">&lt; You're in the main context section, split file</font><br><font color="#004080">&gt; start</font><br><font color="#800000">&lt; Entering sub-section</font><br><font color="#004080">&gt; test_section</font><br><font color="#800000">&lt; You're on the sub-section</font><br><font color="#004080">&gt; test_split_section</font><br><font color="#800000">&lt; You're in the sub-context section, split file</font><br><font color="#004080">&gt; abandon</font><br><font color="#800000">&lt; Going out of the sub-section</font><br><font color="#004080">&gt; test_section</font><br><font color="#800000">&lt; You're on the main section</font><br><font color="#004080">&gt; abandon</font><br><font color="#800000">&lt; Going out of the main section</font><br><font color="#004080">&gt; test_section</font><br><font color="#800000">&lt; You're out of the main section</font></font></p> <p> </p> <p>With context zones, you can define advanced conversation flows, "restricted areas", triggers, and even simulate conversation dialogs by using multiple zones.</p>
