<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>CodingMonk</title>
        <link>http://codingmonk.com/Default.aspx</link>
        <description />
        <language>en-US</language>
        <copyright>Jim Fisher</copyright>
        <managingEditor>Jim@CodingMonk.com</managingEditor>
        <generator>Subtext Version 1.9.5.177</generator>
        <image>
            <title>CodingMonk</title>
            <url>http://codingmonk.com/images/RSS2Image.gif</url>
            <link>http://codingmonk.com/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Subtext &amp; JavaScript</title>
            <link>http://codingmonk.com/archive/2008/08/17/subtext--javascript.aspx</link>
            <description>&lt;p&gt;It's been a few months, but I've finally gotten around to finishing an article promised months ago about &lt;a href="http://www.codingmonk.com/archive/2008/08/17/configuring-subtext-for-blogging-with-word-2007.aspx"&gt;configuring Subtext 1.9.5b to support images when blogging from Word 2007&lt;/a&gt;. As chance would have it, this comes just a week after &lt;a href="http://haacked.com/archive/2008/08/10/subtext-2.0-released.aspx"&gt;Subtext 2.0 is released&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Additionally, I've updated and posted a document written a few years ago but never released offering ways to &lt;a href="http://www.codingmonk.com/archive/2008/08/17/tips-for-building-a-javascript-library.aspx"&gt;organize your JavaScript&lt;/a&gt; library. This article comes along side a new zone to this site: &lt;a href="http://www.codingmonk.com/category/6.aspx"&gt;JavaScript&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://codingmonk.com/aggbug/22.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Fisher</dc:creator>
            <guid>http://codingmonk.com/archive/2008/08/17/subtext--javascript.aspx</guid>
            <pubDate>Mon, 18 Aug 2008 04:52:34 GMT</pubDate>
            <comments>http://codingmonk.com/archive/2008/08/17/subtext--javascript.aspx#feedback</comments>
            <wfw:commentRss>http://codingmonk.com/comments/commentRss/22.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Tips for Building a JavaScript Library</title>
            <category>JavaScript</category>
            <link>http://codingmonk.com/archive/2008/08/17/tips-for-building-a-javascript-library.aspx</link>
            <description>&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;You're an experienced developer. You learned a long time ago how to make your code generic and factor it for optimum reusability, neatly organizing it into tight, independent packages. Need a multithreaded web scrapper? You have a C# assembly that does that, thank you. Logging to the event viewer from T-SQL? No problem, there's that script you developed a few years ago. Want transformed text embedded in a graphic? Got it covered. The toolkit you've built over the years equips you to easily handle almost any task. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Almost. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Well… There is that bit of untidiness with your JavaScript. But everyone has that, right? I mean, with the hundreds of snippets smattered across the internet how could anyone keep those straight? Sure, you've made the obligatory attempt. You put the most often used routines into a single common include file. But the file grows with almost every new project, and each project leveraging this file uses only a fraction of its contents. The practice of monolithic includes is… unsatisfying. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Fear not. There is a better way. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;strong&gt;About this Article&lt;/strong&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;This article describes some of the impediments that make fashioning and maintaining a library in JavaScript troublesome and discusses some techniques for surmounting these obstacles. These techniques have been adopted by CodingMonk and are manifest as the JACL (JavaScript Application Code Library) framework. As such, most of the examples are given in that context, yet the techniques described here lend themselves equally well to a personal implementation. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;The code depicted here has been tested under both the Firefox and Internet Explorer browsers, including Microsoft's implementation of HTAs (HTML applications). I suspect that these techniques could also be ported to additional browsers (e.g. Opera, Safari) with minimal effort. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Before going further, I'd like to make it clear that my way is not the only way. There are a number of gifted JavaScript developers around the world and I expect there exist several additional techniques not covered here. Please keep in mind that what works well for me may not fit well in the preferences of another developer. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;strong&gt;What Makes a Code Library? &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;A fundamental preconception that people have when they hear the word "library" is that it is a collection of smaller parts. Although I can lump all of my scripts into a single reusable file and call it "Jim's library", that doesn't really hold true to the spirit of the word. Likewise, just as we wouldn't checkout every book from the shelves of a real library when researching English history, we shouldn't have to download the complete code when we're only using one or two of its features. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;So, &lt;em&gt;our library should be organized into functional modules from which we can pick and choose what we need&lt;/em&gt;. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;This deceptively simple diktat is absent from the majority of JavaScript "libraries" available on the internet. Why? Because modules inject unexpected complexity into a library, especially highly functional ones leveraging other modules as dependencies. We'll identify some for these complexities and address them now. When we're finished, we'll have a basis upon which to build a working, expandable framework for our JavaScript library. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;strong&gt;Modules Including Modules &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;As a code library matures, it's almost a given that one module will eventually need to include another. In JACL, for example, the Log module is automatically included by the Core module, so logging functionality is always available. Another example: each of JACL's self-updating controls leverages an AJAX implementation housed in the ServerRequest module. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;So how do we include a JavaScript file from within another JavaScript file? Obviously the most common way to include JavaScript from HTML is with the script tag: &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt; &lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;script src="http://www.codingmonk.com/jacl/jacl.js"&amp;gt;&amp;lt;/script&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;span style="FONT-FAMILY: Arial"&gt;So from within a JavaScript file, one possibility is to leverage &lt;/span&gt;&lt;span style="FONT-FAMILY: Courier New"&gt;document.write()&lt;/span&gt;&lt;span style="FONT-FAMILY: Arial"&gt; to inject customized script tags whenever a library module needs to meet a dependency. A la: &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt; &lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;document.write( "&amp;lt;script src='http://www.codingmonk.com/jacl/jacl.js'&amp;gt; &amp;lt;/script&amp;gt;");     &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;One complication associated with dynamic inclusion of JavaScript: it is not immediately obvious when the included file has successfully loaded. Despite their similarities, it's easy to forget that the above two lines are not exactly equivalent. To be precise: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;ul style="MARGIN-LEFT: 54pt"&gt;
    &lt;li&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;The first, declared within the HTML document, includes the JavaScript file while the page is first loading, but before scripts are run. &lt;/span&gt;&lt;/li&gt;
    &lt;li&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;The second, processed after the page has finished loading and declared scripts are running, identifies subsequent scripts that the browser should load when it gets the opportunity. &lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;So as rule: JavaScript included from JavaScript is not immediately available, but JavaScript included from a tag in the unmodified HTML document is. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;To demonstrate, we can do this: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;html&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;script src="http://www.codingmonk.com/jacl/jacl.js"&amp;gt;&amp;lt;/script&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;script language = "JavaScript"&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;jacl.appMain = function(){alert("Something wicked this way comes...");}; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;/script&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;/html&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;But we can't we do this: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;html&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;script language="JavaScript"&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 72pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;document.write( "&amp;lt;script src='http://www.codingmonk.com/jacl/jacl.js'&amp;gt;&amp;lt;/script&amp;gt;"); &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 72pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;jacl.appMain = function(){alert("Something wicked generates an error...");}; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;/script&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;/html&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Because the second example produces an error message in the spirit of "jacl is undefined". &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;A more sophisticated alternative is to leverage the browser DOM, like so: &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt; &lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;html&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;script language="JavaScript"&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;var o=document.createElement("script"); &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;    o.src="http://www.codingmonk.com/jacl/jacl.js"; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;    o.onreadystatechange = function(){ &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 108pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;if(this.readyState == "loaded"){ &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 144pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;jacl.appMain = function(){alert("Something wicked this way comes...");}; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 108pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;} &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;}; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;document.body.appendChild(o);     &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;/script&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;/html&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;span style="FONT-FAMILY: Arial"&gt;Use of the DOM to dynamically load JavaScript provides a solution to our problem in the form of the &lt;/span&gt;&lt;span style="FONT-FAMILY: Courier New"&gt;onreadystatechange&lt;/span&gt;&lt;span style="FONT-FAMILY: Arial"&gt; event. This event fires only when the script has loaded completely, at which point we can reference functions and objects provided by the included file with impunity. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;strong&gt;Initial Module Inclusion &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Despite the DOM example in the last section, the practice of including JavaScript from JavaScript gains us nothing when used where traditional HTML script tags are possible. If used appropriately, it enables us to manage our library entries and their dependencies intelligently, but it is still necessary to include the first module by hand. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;This brings us full-circle to the first code snippet listed in this article: &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt; &lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;script src="http://www.codingmonk.com/jacl/jacl.js"&amp;gt;&amp;lt;/script&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;As it turns out, there is considerable usefulness in including an initial module as we would include a traditional script file. It provides for us select core routines without having to wait for a load event, including implementation of principals discussed above which load modules programmatically. Additionally, it gives us a place to perform library initialization. This can include, among other things, an application-defined entry point where we can be certain all library modules are loaded and ready. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;To demonstrate, below is a working example of an HTML page leveraging JACL's Plot module to draw a sine wave. For those that are curious, it can cut-and-pasted into an html file and viewed it in any browser. &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt; &lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;html&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;body&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;script src="http://www.codingmonk.com/jacl/jacl.js"&amp;gt;&amp;lt;/script&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;script language="JavaScript"&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;    jacl.use("jaclPlot"); &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;    jacl.appMain=function(){ &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;        jacl.plot.setOrigin(50,100); &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;        jacl.log.info('Graphing sine wave...'); &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;        for(var t=0;t&amp;lt; 300;t++) &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;            jacl.plot.point(t,Math.sin(t/30)*30); &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;        }; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;/script&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;/body&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;&amp;lt;/html&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;span style="FONT-FAMILY: Arial"&gt;Notice that our initial inclusion of the now familiar JACL Core module is done explicitly as an HTML tag. This ensures that the library's objects (in this case the &lt;/span&gt;&lt;span style="FONT-FAMILY: Courier New"&gt;jacl&lt;/span&gt;&lt;span style="FONT-FAMILY: Arial"&gt; object) are present, as are library defined code. In the JACL framework, this includes the &lt;/span&gt;&lt;span style="FONT-FAMILY: Courier New"&gt;use&lt;/span&gt;&lt;span style="FONT-FAMILY: Arial"&gt; method, which is simply a refined implementation of the DOM principals discussed in the previous section, and the&lt;/span&gt;&lt;span style="FONT-FAMILY: Courier New"&gt; appMain&lt;/span&gt;&lt;span style="FONT-FAMILY: Arial"&gt; method which is similar in principal to the &lt;/span&gt;&lt;span style="FONT-FAMILY: Courier New"&gt;onreadystatechange&lt;/span&gt;&lt;span style="FONT-FAMILY: Arial"&gt; event but fires only once when &lt;strong&gt;&lt;em&gt;all&lt;/em&gt;&lt;/strong&gt; modules have finally been loaded. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;strong&gt;Avoiding Multiple Inclusions &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Another complexity inherent in the practice of &lt;em&gt;modules-including-modules&lt;/em&gt; occurs when two modules share the same dependency. If not handled, the same module can be included twice. The worst case scenario results in self-referencing recursion and a page that never finishes loading. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;The simplest solution is to set a flag when a module is included for the first time, doing nothing on subsequent inclusions. By leveraging our object hierarchy, this is almost laughably easy as the individual objects created by a module act as flags simply by virtue of their existence: &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt; &lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;if(jacl.plot==null) { //already created? &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;    jacl.plot=new jacl_plot(); //no? then let's create an instance &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;    // implementation goes here &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;} &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;The only drawback to this is that, while easy, the approach must be enforced across all library modules. A better alternative, one that can be implemented in the library object itself is to track which modules have been already been requested and don't add them via the DOM more than once. &lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;strong&gt;Establishing a Library's Location &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Astute observers will notice one important nuance in the sine wave example: &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt; &lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;jacl.use("jaclPlot"); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;span style="FONT-FAMILY: Arial"&gt;The &lt;/span&gt;&lt;span style="FONT-FAMILY: Courier New"&gt;use&lt;/span&gt;&lt;span style="FONT-FAMILY: Arial"&gt; method does not require a fully qualified file path. At first glance this seems a trivial feature. After all, if we need to specify the URL when we include one module, it is only a small inconvenience to provide the URL with subsequent inclusions. The real problem arises, again, when modules include other modules. In the example where we included modules with the DOM, the path was hard-coded, as in: &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;o.src="http://www.codingmonk.com/jacl/jaclPlot.js"; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;This isn't going to do us any good if we try to access our library locally, or if we move it to a different domain. What we need is for the module to determine the library's location relative to the client. As it turns out, this isn't too difficult. Since we're including an initial core module with a fully qualified filename all we have to do search the document's script objects and parse the path from the correct one: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;var path=""; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;for(t=0;t&amp;lt;document.scripts.length;t++){ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;        var val=document.scripts[t].outerHTML.toLowerCase(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;        if(val.indexOf("jacl.js")==-1) continue; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;        var s=val.indexOf("src=\""); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;        if(s!=-1){ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;            s+=5; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;            path=val.substring(s,val.indexOf("jacl",s)); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;            break; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;        } &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;    } &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;span style="FONT-FAMILY: Arial"&gt;So the &lt;/span&gt;&lt;span style="FONT-FAMILY: Courier New"&gt;use&lt;/span&gt;&lt;span style="FONT-FAMILY: Arial"&gt; method knows to expand: &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;jaclplot &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;into &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;http://www.codingmonk.com/jacl/jaclplot.js&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;by using the resulting path variable. Of course, storing the path as a global variable clutters the namespace. This is just one of several advantages of leveraging an object hierarchy for our JavaScript library… &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;strong&gt;Organizing a Hierarchy &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;The best, most useful of libraries can suffer and die because it is not kept organized. As libraries grow, they become more difficult to keep arranged. No matter how many modules your library is broken down into, if the net result is just a chaotic bundle of routines, then the library hasn't helped as much as it could. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;span style="FONT-FAMILY: Arial"&gt;Namespace hierarchies help us to stay organized. More than just factoring code into modules, this technique structures our code in precise and predictable ways. Notice from our examples how every use of the JACL library stems either directly or indirectly from the global &lt;/span&gt;&lt;span style="FONT-FAMILY: Courier New"&gt;jacl&lt;/span&gt;&lt;span style="FONT-FAMILY: Arial"&gt; object. JACL's implementation of the previous path-finding example populates a member variable rather than a global one: &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;    jacl.path &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;By doing this, we need not worry ourselves with the possibility of naming collisions, where another module or otherwise appropriated script defines a variable named "path" too. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Continuing the review of the fully working sine-wave example given previously, notice that JACL's logging module adds an object which encapsulates various pieces of logging functionality: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;jacl.log.trivial("Here is a message"); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Other JACL modules go to greater lengths to categorize their code: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: Courier New"&gt;jacl.input.textbox.applyEditMask(tbInput, "###-##-####"); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;How diverse you choose to make your hierarchy is, of course, a personal preference. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;strong&gt;Review a real implementation &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;As was pointed out numerous times, the techniques proposed in this article are more than theoretical. For a complete working example, one moderately more fleshed out, I highly recommend taking a look at the most recent implementation of Coding Monk's JACL framework: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p style="TEXT-ALIGN: center"&gt;&lt;a href="http://www.codingmonk.com/jacl/downloads/jacl.zip"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;www.codingmonk.com/jacl/downloads/jacl.zip&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Happy coding! &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;/span&gt; &lt;/p&gt;&lt;img src="http://codingmonk.com/aggbug/21.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Fisher</dc:creator>
            <guid>http://codingmonk.com/archive/2008/08/17/tips-for-building-a-javascript-library.aspx</guid>
            <pubDate>Mon, 18 Aug 2008 03:19:40 GMT</pubDate>
            <wfw:comment>http://codingmonk.com/comments/21.aspx</wfw:comment>
            <comments>http://codingmonk.com/archive/2008/08/17/tips-for-building-a-javascript-library.aspx#feedback</comments>
            <wfw:commentRss>http://codingmonk.com/comments/commentRss/21.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Configuring Subtext for Blogging with Word 2007</title>
            <category>Subtext</category>
            <link>http://codingmonk.com/archive/2008/08/17/configuring-subtext-for-blogging-with-word-2007.aspx</link>
            <description>&lt;p&gt;As part of my political agenda, in a &lt;a href="http://www.codingmonk.com/archive/2008/05/15/configuring-word-2007-for-blogging-to-subtext.aspx"&gt;recent post&lt;/a&gt; I walked through the steps of configuring Word 2007's blogging features to work with Subtext.  At the end of that article, I promised to review the code changes required to make Subtext accept pictures from Word 2007.  The fix I detail here consists of relatively minor code changes, limited to two c# files in the Subtext.Framework project:
&lt;/p&gt;&lt;ul style="margin-left: 72pt"&gt;&lt;li&gt;MetaWeblog.cs
&lt;/li&gt;&lt;li&gt;MetaWeblogAPI.cs
&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you regularly compile the Subtext source code, you'll find making these changes a snap.  If not, you might find it easier to skip the rest of this article, navigate to your site's bin directory, rename the Subtext.Framework.dll file and drop &lt;a href="http://www.codingmonk.com/downloads/Subtext.Framework.dll-1.9.5b-support.Word.2007.zip"&gt;this one&lt;/a&gt; in its place. 
&lt;/p&gt;&lt;p&gt;Before moving forward, I should note that the changes described are against the Subtext 1.9.5b code base and future versions of the code base probably have this incompatibility addressed, so a bit of advice: make sure which version of Subtext you are using before you begin digging into the internals.  
&lt;/p&gt;&lt;p&gt;&lt;strong&gt;MetaWeblogAPI.cs
&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;If you crack open the MetaWeblogAPI.cs file (under &lt;span style="font-family:Courier New"&gt;Subtext.Framework.XmlRpc&lt;/span&gt;) and search for the &lt;span style="font-family:Courier New"&gt;newMediaObject&lt;/span&gt; method, you'll find the following under the &lt;span style="font-family:Courier New"&gt;IMetaWeblog&lt;/span&gt; interface:
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;[XmlRpcMethod(&lt;span style="color:#a31515"&gt;"metaWeblog.newMediaObject"&lt;/span&gt;,&lt;br /&gt;Description = &lt;span style="color:#a31515"&gt;"Uploads an image, movie, song, or other media "&lt;/span&gt;&lt;br /&gt;+ &lt;span style="color:#a31515"&gt;"using the metaWeblog API. Returns the metaObject struct."&lt;/span&gt;)]
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;mediaObjectInfo newMediaObject(&lt;span style="color:blue"&gt;object&lt;/span&gt; blogid, &lt;span style="color:blue"&gt;string&lt;/span&gt; username, &lt;br /&gt;
			&lt;span style="color:blue"&gt;string&lt;/span&gt; password, mediaObject mediaobject);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;Note the &lt;span style="font-family:Courier New"&gt;blogid&lt;/span&gt; parameter is of type &lt;span style="font-family:Courier New"&gt;object&lt;/span&gt;, unlike every other method in the interface, which all support &lt;span style="font-family:Courier New"&gt;blogid&lt;/span&gt; parameters of type &lt;span style="font-family:Courier New"&gt;string&lt;/span&gt;.  The easiest fix in this module is to change the change the parameter type to &lt;span style="font-family:Courier New"&gt;string&lt;/span&gt;, and I suspect that this alone might solve the issue, but a more thorough approach, one that leaves compatibility for other applications that may actually use the object-based &lt;span style="font-family:Courier New"&gt;blogid&lt;/span&gt;, is to add a more specific declaration or two.  I chose this path of overkill, rather than that of minimalism by adding support for both &lt;span style="font-family:Courier New"&gt;string &lt;/span&gt;and &lt;span style="font-family:Courier New"&gt;int&lt;/span&gt; types; while not strictly necessary, it was quite easy to do.  The full definition of the &lt;span style="font-family:Courier New"&gt;newMediaObject&lt;/span&gt; declaration appears below, with the additions surrounded with a dotted border: 
&lt;/p&gt;&lt;p&gt;     
 &lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:548px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 109px"&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  dashed black 1.5pt; border-left:  dashed black 1.5pt; border-bottom:  dashed black 1.5pt; border-right:  dashed black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;[&lt;span style="color:#2b91af"&gt;XmlRpcMethod&lt;/span&gt;(&lt;span style="color:#a31515"&gt;"metaWeblog.newMediaObject"&lt;/span&gt;,&lt;br /&gt;Description = &lt;span style="color:#a31515"&gt;"Uploads an image, movie, song, or other media " &lt;br /&gt;&lt;/span&gt;+ &lt;span style="color:#a31515"&gt;"using the metaWeblog API. Returns the metaObject struct."&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color:#2b91af"&gt;mediaObjectInfo&lt;/span&gt; newMediaObject(&lt;span style="color:blue"&gt;string&lt;/span&gt; blogid, &lt;span style="color:blue"&gt;string&lt;/span&gt; username,&lt;br /&gt;    &lt;span style="color:blue"&gt;string&lt;/span&gt; password, &lt;span style="color:#2b91af"&gt;mediaObject&lt;/span&gt; mediaobject);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;[&lt;span style="color:#2b91af"&gt;XmlRpcMethod&lt;/span&gt;(&lt;span style="color:#a31515"&gt;"metaWeblog.newMediaObject"&lt;/span&gt;,&lt;br /&gt;Description = &lt;span style="color:#a31515"&gt;"Uploads an image, movie, song, or other media "&lt;/span&gt;&lt;br /&gt;+ &lt;span style="color:#a31515"&gt;"using the metaWeblog API. Returns the metaObject struct."&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color:#2b91af"&gt;mediaObjectInfo&lt;/span&gt; newMediaObject(&lt;span style="color:blue"&gt;int&lt;/span&gt; blogid, &lt;span style="color:blue"&gt;string&lt;/span&gt; username, &lt;br /&gt;    &lt;span style="color:blue"&gt;string&lt;/span&gt; password, &lt;span style="color:#2b91af"&gt;mediaObject&lt;/span&gt; mediaobject);&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 109px"&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  solid white 0.25pt; border-bottom:  solid white 0.25pt; border-right:  solid white 0.25pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;br /&gt;[&lt;span style="color:#2b91af"&gt;XmlRpcMethod&lt;/span&gt;(&lt;span style="color:#a31515"&gt;"metaWeblog.newMediaObject"&lt;/span&gt;,&lt;br /&gt;Description = &lt;span style="color:#a31515"&gt;"Uploads an image, movie, song, or other media "&lt;/span&gt;&lt;br /&gt;+ &lt;span style="color:#a31515"&gt;"using the metaWeblog API. Returns the metaObject struct."&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color:#2b91af"&gt;mediaObjectInfo&lt;/span&gt; newMediaObject(&lt;span style="color:blue"&gt;object&lt;/span&gt; blogid, &lt;span style="color:blue"&gt;string&lt;/span&gt; username, &lt;br /&gt;    &lt;span style="color:blue"&gt;string&lt;/span&gt; password, &lt;span style="color:#2b91af"&gt;mediaObject&lt;/span&gt; mediaobject);&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;These are, of course, only slight variations on the original declaration.
&lt;/p&gt;&lt;p&gt;&lt;strong&gt;MetaWeblog.cs&lt;/strong&gt;
	&lt;/p&gt;&lt;p&gt;Having declared the additional forms of &lt;span style="font-family:Courier New"&gt;newMediaObject&lt;/span&gt; that Subtext will support, we are half way complete.  The final changes that are to be made are contained in the &lt;span style="color:#2b91af; font-family:Courier New; font-size:10pt"&gt;MetaWeblog&lt;/span&gt; class.  Search for the implementation of &lt;span style="font-family:Courier New"&gt;newMediaObject&lt;/span&gt; and you'll find the original signature:
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;public&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;mediaObjectInfo&lt;/span&gt; newMediaObject(&lt;span style="color:blue"&gt;object&lt;/span&gt; blogid, &lt;span style="color:blue"&gt;string&lt;/span&gt; username, &lt;br /&gt;
			&lt;span style="color:blue"&gt;string&lt;/span&gt; password, &lt;span style="color:#2b91af"&gt;mediaObject&lt;/span&gt; mediaobject)&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;Note the &lt;span style="font-family:Courier New"&gt;blogid&lt;/span&gt; parameter with the type &lt;span style="font-family:Courier New"&gt;object&lt;/span&gt;.  I found it best to not change the existing code.  Instead, we need only to implement the two additions defined for the interface supporting the two alternate parameter types.  Implementing pass-through methods for this is the least painful of approaches:
&lt;/p&gt;&lt;div style="margin-left: 35pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:545px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 152px"&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  dashed black 1.5pt; border-left:  dashed black 1.5pt; border-bottom:  dashed black 1.5pt; border-right:  dashed black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;public&lt;/span&gt;
								&lt;span style="color:#2b91af"&gt;mediaObjectInfo&lt;/span&gt; newMediaObject(&lt;span style="color:blue"&gt;int&lt;/span&gt; blogid, &lt;br /&gt;    &lt;span style="color:blue"&gt;string&lt;/span&gt; username, &lt;span style="color:blue"&gt;string&lt;/span&gt; password, &lt;br /&gt;    &lt;span style="color:#2b91af"&gt;mediaObject&lt;/span&gt; mediaobject) &lt;br /&gt;{&lt;br /&gt;    &lt;span style="color:blue"&gt;return&lt;/span&gt; newMediaObject(blogid.ToString(), username, &lt;br /&gt;        password, mediaobject);&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:blue"&gt;public&lt;/span&gt;
								&lt;span style="color:#2b91af"&gt;mediaObjectInfo&lt;/span&gt; newMediaObject(&lt;span style="color:blue"&gt;string&lt;/span&gt; blogid, &lt;br /&gt;    &lt;span style="color:blue"&gt;string&lt;/span&gt; username, &lt;span style="color:blue"&gt;string&lt;/span&gt; password, &lt;br /&gt;    &lt;span style="color:#2b91af"&gt;mediaObject&lt;/span&gt; mediaobject)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color:blue"&gt;return&lt;/span&gt; newMediaObject((&lt;span style="color:blue"&gt;object&lt;/span&gt;)blogid, username, &lt;br /&gt;        password, mediaobject);&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;And that's pretty much it for changes to Subtext.  After we compile this and deploy the resulting modified &lt;span style="font-family:Courier New"&gt;Subtext.Framework&lt;/span&gt; assembly, Subtext should support images from Word 2007.
&lt;/p&gt;&lt;img src="http://codingmonk.com/aggbug/20.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Fisher</dc:creator>
            <guid>http://codingmonk.com/archive/2008/08/17/configuring-subtext-for-blogging-with-word-2007.aspx</guid>
            <pubDate>Mon, 18 Aug 2008 03:02:12 GMT</pubDate>
            <wfw:comment>http://codingmonk.com/comments/20.aspx</wfw:comment>
            <comments>http://codingmonk.com/archive/2008/08/17/configuring-subtext-for-blogging-with-word-2007.aspx#feedback</comments>
            <wfw:commentRss>http://codingmonk.com/comments/commentRss/20.aspx</wfw:commentRss>
        </item>
        <item>
            <title>As Part of My Nonsense…</title>
            <category>General</category>
            <link>http://codingmonk.com/archive/2008/08/17/as-part-of-my-nonsense.aspx</link>
            <description>&lt;p&gt;If you've been reading my blog for long, you may have noticed a common trend across some of my larger pieces: a bit of text expressing background to the article and indicating that it is part of a larger, personal effort: &lt;/p&gt;
&lt;ul style="MARGIN-LEFT: 72pt"&gt;
    &lt;li&gt;"As part of my political agenda…" &lt;/li&gt;
    &lt;li&gt;"As part of my endeavors toward evangelizing the free world…" &lt;/li&gt;
    &lt;li&gt;"As part of my plan to stick it to &lt;em&gt;the man&lt;/em&gt;…" &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It doesn't take much review to realize that these are nonsensical statements, not to be taken literally, which serve as a form of unapparent signature when my articles are viewed individually, but which clearly mark my work when viewed as a whole. &lt;/p&gt;&lt;img src="http://codingmonk.com/aggbug/19.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Fisher</dc:creator>
            <guid>http://codingmonk.com/archive/2008/08/17/as-part-of-my-nonsense.aspx</guid>
            <pubDate>Sun, 17 Aug 2008 16:33:28 GMT</pubDate>
            <comments>http://codingmonk.com/archive/2008/08/17/as-part-of-my-nonsense.aspx#feedback</comments>
            <wfw:commentRss>http://codingmonk.com/comments/commentRss/19.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Configuring Word 2007 for Blogging to Subtext</title>
            <category>Subtext</category>
            <link>http://codingmonk.com/archive/2008/05/15/configuring-word-2007-for-blogging-to-subtext.aspx</link>
            <description>&lt;p&gt;As part of my need to clearly express myself, I've been writing and posting articles on various sites for some time and, for me at least, the process has always been a painful one.  For years I'd write the articles in Word, paste the completed document into Visual Studio, clean up the resulting HTML and formatting by switching back and forth between the source and the display panels, and finally upload the completed HTML to my site's database.  Not exactly a roadblock, but this was certainly a speed bump in the creative process.
&lt;/p&gt;&lt;p&gt;Beginning with Word 2007, Microsoft introduced a feature that removes the middle man and significantly streamlines the process of publishing articles online:  Word now talks directly to blogging systems, including &lt;a href="http://www.subtextproject.com"&gt;Subtext&lt;/a&gt; (the blogging framework upon which this site is based)!
&lt;/p&gt;&lt;p&gt;&lt;a href="http://office.microsoft.com/en-us/word/HA102341301033.aspx"&gt;I'm&lt;/a&gt;
		&lt;a href="http://www.irishdev.com/blogs/kieranlynam/archive/2006/06/28/1639.aspx"&gt;not&lt;/a&gt;
		&lt;a href="http://www.videojug.com/film/how-to-blog-through-word-2007"&gt;the&lt;/a&gt;
		&lt;a href="http://geekswithblogs.net/viktorbergman/archive/2007/02/25/107242.aspx"&gt;first&lt;/a&gt;
		&lt;a href="http://everything.typepad.com/blog/2007/04/post_to_your_bl.html"&gt;to&lt;/a&gt;
		&lt;a href="http://blog.jonudell.net/2007/02/19/blogging-from-word-2007-crossing-the-chasm/"&gt;post&lt;/a&gt;
		&lt;a href="http://skattertech.com/2007/02/word-07-supports-wordpress/"&gt;on&lt;/a&gt;
		&lt;a href="http://nevyan.blogspot.com/2007/09/publish-your-blog-using-word-2007.html"&gt;Word's&lt;/a&gt;
		&lt;a href="http://blog.case.edu/bes7/2006/11/05/testing_word_2007_blog_integration"&gt;new&lt;/a&gt;
		&lt;a href="http://msmvps.com/blogs/ad/archive/2007/01/07/posting-with-word-2007.aspx"&gt;blogging&lt;/a&gt;
		&lt;a href="http://word2007bible.herbtyson.com/2008/04/17/editing-previously-posted-blog-entries/"&gt;features&lt;/a&gt;.  In fact, I'm a bit late to the game; however, much of the research I turned up on Word 2007's blogging functionality didn't actually apply to what I was trying to do and a few sites alluded to steps that needed to be taken but didn't provide much in the way of details.  So this post documents my own personal experiences on configuring Word to work with Subtext.  On the whole, I thought it was relatively easy and I find blogging with Word 2007 a positive change, the advantages of which outweigh the drawbacks.  Your mileage may vary. 
&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Basic Word Configuration
&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Configuring Word2007 for blogging with Subtext is a snap and if you've never done it before, you'll get prompted to configure just by opening a new, blank blog entry.  That is: 
&lt;/p&gt;&lt;ul style="margin-left: 38pt"&gt;&lt;li&gt;click your friendly office button&lt;strong&gt;:&lt;img src="http://codingmonk.com/images/codingmonk_com/051508_0631_Configuring1.png" alt="" /&gt;&lt;/strong&gt;
		&lt;/li&gt;&lt;li&gt;select &lt;em&gt;New&lt;/em&gt;
		&lt;/li&gt;&lt;li&gt;&lt;div&gt;double click the &lt;strong&gt;&lt;em&gt;New blog post&lt;/em&gt;&lt;/strong&gt; option:
&lt;/div&gt;&lt;p style="margin-left: 69pt"&gt;&lt;img src="http://codingmonk.com/images/codingmonk_com/051508_0631_Configuring2.png" alt="" /&gt;
			&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;At this point, Word detects that you have no blogging accounts setup and prompts you to create a new one.  Word comes preconfigured with a slew of blog providers, but at the time of this writing, Subtext is not one of them.  That's okay though; as I said before, configuring Word is really easy.  So from the Blog dropdown, just choose "other" and click the Next button: 
&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;img src="http://codingmonk.com/images/codingmonk_com/051508_0631_Configuring3.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;Beyond the username password (which you presumably know if you &lt;img align="right" src="http://codingmonk.com/images/codingmonk_com/051508_0631_Configuring4.png" alt="" /&gt;actually blog to your site), there are only two settings to configure:
&lt;/p&gt;&lt;ul style="margin-left: 54pt"&gt;&lt;li&gt;&lt;strong&gt;The API dropdown&lt;/strong&gt; - For Subtext, this should always be set to MetaWebLog.
&lt;/li&gt;&lt;li&gt;&lt;div&gt;&lt;strong&gt;The Blog Post URL textbox &lt;/strong&gt;– This is a bit less obvious, but it is the full URL of your Subtext site plus:
&lt;/div&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;/services/metablogapi.aspx 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;That is, if your Subtext installation rests at &lt;span style="font-family:Courier New"&gt;www.mblog.com&lt;/span&gt;, then your Blog Post URL would be:
&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;http://www.mblog.com/services/metablogapi.aspx
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Those running short on faith (I'll pray for you, my brothers) might try to locate this file in their site's directory structure, just for reassurance that they have the URL correct.  This will likely convince them that they managed to get their installation of Subtext fouled up when they find that this file does not actually exist.  Don't be bothered by this.  Subtext leverages a form of URL rewriting to make this address work; so enter this magic URL along with your username and password, secure in the knowledge that Word will immediately award you with a success or an error message as soon as you press the OK button.
&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Special Notes on Picture Options
&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;To configure pictures, press the "Picture Options" button to pull up yet another dialog:
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;img src="http://codingmonk.com/images/codingmonk_com/051508_0631_Configuring5.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;The default selection "My blog provider" is the correct setting for SubText, and for Subtext, this dialog need only be closed (press "OK").  Having made no changes, you might think that you can skip this step entirely, but my experience in this suggests that this open-and-close step is required and that support for pictures do not work unless this is done. 
&lt;/p&gt;&lt;p&gt;At this point I should mention that, as of the 1.9.5 release, SubText and Word 2007 do not exchange images.  That is, pictures embedded in your post in Word, will not appear in your post when it's been published.  This can be made to happen, and it's quite easy, really.  I'll cover this in my next post.
&lt;/p&gt;&lt;img src="http://codingmonk.com/aggbug/16.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Fisher</dc:creator>
            <guid>http://codingmonk.com/archive/2008/05/15/configuring-word-2007-for-blogging-to-subtext.aspx</guid>
            <pubDate>Thu, 15 May 2008 06:32:03 GMT</pubDate>
            <wfw:comment>http://codingmonk.com/comments/16.aspx</wfw:comment>
            <comments>http://codingmonk.com/archive/2008/05/15/configuring-word-2007-for-blogging-to-subtext.aspx#feedback</comments>
            <wfw:commentRss>http://codingmonk.com/comments/commentRss/16.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Done Enough</title>
            <link>http://codingmonk.com/archive/2008/05/10/done-enough.aspx</link>
            <description>&lt;p&gt;It's been roughly two months since I &lt;a href="http://www.codingmonk.com/archive/2008/03/09/surprise--everythings-gone.aspx"&gt;tossed it all away and started over&lt;/a&gt;, but I think the site is close enough to actually begin using now. My &lt;a href="http://www.codingmonk.com/archive/2008/04/15/a-bit-left-to-go.aspx"&gt;last post&lt;/a&gt; listed six items I arbitrarily mandated as the criteria by with the site's skinning could be judged was "done": &lt;/p&gt;
&lt;ul style="MARGIN-LEFT: 54pt"&gt;
    &lt;li&gt;Add support for post series &lt;/li&gt;
    &lt;li&gt;Implement syndication links &lt;/li&gt;
    &lt;li&gt;Update comment system &lt;/li&gt;
    &lt;li&gt;Polish up the UI (buttons) &lt;/li&gt;
    &lt;li&gt;Add a Subtext category &lt;/li&gt;
    &lt;li&gt;Incorporate traditional blog controls (like a tag clouds and archive listing) &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Well, the first five are complete. "Done enough," I say. &lt;/p&gt;
&lt;p&gt;So you might think the traditional blog controls would be the easiest to cross off my list, and you might be right. I'll definitely get around to it, but at the moment these seem less important to me. After all, there need to be blog postings before these controls become useful. &lt;/p&gt;
&lt;p&gt;In addition to the five above, I also added a few additional features which did not exist before: &lt;/p&gt;
&lt;ul style="MARGIN-LEFT: 54pt"&gt;
    &lt;li&gt;A layout button to expand and collapse the width of the site &lt;/li&gt;
    &lt;li&gt;A Preview button to preview what comments will look like once posted &lt;/li&gt;
    &lt;li&gt;A modification to the Subtext code base to allow Word 2007 to post images (I use Word as my blogging tool) &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This last item, blogging to Subtext with Word 2007, will be the subject matter of my first post, by the way. &lt;/p&gt;
&lt;p&gt;Stay tuned.&lt;/p&gt;&lt;img src="http://codingmonk.com/aggbug/15.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Fisher</dc:creator>
            <guid>http://codingmonk.com/archive/2008/05/10/done-enough.aspx</guid>
            <pubDate>Sun, 11 May 2008 03:46:41 GMT</pubDate>
            <comments>http://codingmonk.com/archive/2008/05/10/done-enough.aspx#feedback</comments>
            <wfw:commentRss>http://codingmonk.com/comments/commentRss/15.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Advanced NPC Creation, Part 3: NPC Actions</title>
            <category>I6</category>
            <link>http://codingmonk.com/archive/2001/07/02/advanced-npc-creation-part-3-npc-actions.aspx</link>
            <description>&lt;p&gt;Verb subroutines do it all. They enforce gravity; they differentiate between light and darkness; they decide where a character can travel. These little routines implement the laws of physics in our game world and govern what can and cannot be done. Yet for some reason, historically they only affect the player character. The game world laws that restrict the player do not bind NPCs. The following code exemplifies: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;object room "room" 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;has light 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with description "This is an empty room." 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;object-&amp;gt;"guard" has animate 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with name 'guard' 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, orders [; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;take: move noun to self; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;print_ret (The)self," takes ",(the)noun,"."; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;] 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;object-&amp;gt;"table" has static supporter with name 'table'; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;object-&amp;gt;-&amp;gt;"apple" has edible with name 'apple'; &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;The guard has now been coded to respond to the "take" order and does so too well. In the above example, he will successfully "take" pretty much anything in scope, even things that he should not be able to: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse; background: #244061" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px"&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;room 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;This is an empty room. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;You can see a guard and a table here.  
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;take table 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;That's fixed in place. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;guard, take table 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;The guard takes the table. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;guard, take self 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;The guard takes yourself. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;It is now pitch dark in here!&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Obviously this sort of "empowered taking" holds a very narrow slice of the "desired NPC abilities" pie. By convention, the filtering of what an NPC cannot do is also coded in the appropriate routine: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, orders [;  !... replace the guard's previous orders routine 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;take: 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(noun hasnt static &amp;amp;&amp;amp; noun~=player){ 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;move noun to self; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;print_ret (The)self," takes ",(the)noun,"."; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;} 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;print_ret (The)self," cannot take that."; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;]&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;For the majority of Inform works, that's the way NPC action is accomplished. Piles and piles of example source code and sample NPCs follow this convention of manipulating the game world directly. There are some drawbacks to this, however: 
&lt;/p&gt;&lt;ul style="margin-left: 54pt"&gt;&lt;li&gt;This technique is repetitious. Putting the same rules in the NPC's reaction routines duplicates code that exists in the library's verb routines. 
&lt;/li&gt;&lt;li&gt;This technique can be overly complex. The library considers numerous variables in its efforts to implement the game world. It is very easy to overlook details when writing this sort of code. For instance, in the above example, the guard cannot pickup the player or objects with the "static" attribute, but there is nothing stopping him from taking either "untouchable" objects, or other animate objects. For instance, the guard could take a key contained inside of a locked, glass box (transparent) without breaking the glass. He could also take another NPC behind a locked, cell door. To imitate the library, we would have to code for these circumstances as well. 
&lt;/li&gt;&lt;li&gt;New verbs, such as "cast spell" or "mount horse" are unavailable to the NPC without additional coding too. 
&lt;/li&gt;&lt;li&gt;This technique does not respect an object's "before" routines, which may interrupt an action. 
&lt;/li&gt;&lt;li&gt;By its very nature, this technique limits NPC design, since everything that an NPC can do must be coded for explicitly. 
&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Fear not, for there is another, more powerful way... &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Redirecting to Verb Routines &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A more intuitive solution is to leverage the verb routines themselves. Successful implementation of this method addresses all of the above drawbacks and actually makes the code more readable. At first glance, it seems a deceptively simple means of implementing NPC actions. Many new developers have posted questions to the RAIF newsgroup asking what was wrong with their code and why redirecting actions doesn't seem to work. The following is an example or redirecting an ordered action using the library's "action and return" operator (&amp;lt;&amp;lt;...&amp;gt;&amp;gt;): 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;object-&amp;gt;"guard" has animate 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with name 'guard' 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, orders [; take: &amp;lt;&amp;lt;take noun&amp;gt;&amp;gt;;] 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;; &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;In the initial test of this example, everything appears to work fine: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse; background: #244061" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px"&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;room 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;This is an empty room. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;You can see a guard and a table (on which is an apple) here. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;guard, get apple 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;Taken.&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;It is not until you look with a little more scrutiny that the flaw in this approach appears: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse; background: #244061" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px"&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt; &amp;gt;i 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;You are carrying: 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;an apple&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;The library's verb routines presume that the player carries out all actions. The player is therefore the one that actually picked up the apple. This is unfortunate, but not insurmountable. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Actor, Good; Player, Bad&lt;/strong&gt;
		&lt;br /&gt;&lt;br /&gt;The standard library is glorious. It is, perhaps, the most useful collection of IF routines ever created. To look upon the Library's code is to be humbled. &lt;br /&gt;&lt;br /&gt;Now then, having appropriately praised the library, we can now proceed with a slightly more critical discussion of it. In particular, if there is one area where I feel the library should have been written differently, it is library verbs and messages. Specifically, these two aspects of the library rely upon the "player" variable, rather than the "actor" variable. See how forcing the player variable to momentarily equal the actor variable almost fixes the above behavior: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt; , orders [save retval; ! ... replace the guard's previous orders routine
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;save=player; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;player=actor; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;&amp;lt;take noun&amp;gt;; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;player=save; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;return retval; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;]&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse; background: #244061" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px"&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;guard, get apple 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;Taken. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;i 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;You are carrying nothing. &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Of course this is simply a patch, and it prevents us from completing our implementation of NPC actions, as we'll see below. A legitimate solution would replace the library's verb and verb-helper routines with slightly modified versions that check the actor variable rather than the player variable. We can do this pretty easily to the "take" and "eat" verbs by cutting-and-pasting the appropriate routines from verblibm.h and then running a search-and-replace against them to change references to "player" into references to "actor": 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;!only slightly changed from the standard library 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;[ TakeSub; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if (onotheld_mode==0 || noun notin actor) 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if (AttemptToTakeObject(noun)) rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if (AfterRoutines()==1) rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;notheld_mode=onotheld_mode; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if (notheld_mode==1 || keep_silent==1) rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;L__M(##Take,1); 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;]; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;[ EatSub; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if (ObjectIsUntouchable(noun)) return; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if (noun hasnt edible) return L__M(##Eat,1,noun); 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if (noun has worn){ 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;L__M(##Drop,3,noun); 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;&amp;lt;Disrobe noun&amp;gt;; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if (noun has worn &amp;amp;&amp;amp; noun in actor) rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;} 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;remove noun; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if (AfterRoutines()==1) rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if (keep_silent==1) rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;L__M(##Eat,2,noun); 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;]; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;[ AttemptToTakeObject item ancestor after_recipient i j k; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;...also needs to be updated since it is called from TakeSub 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;]; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;[ ObjectIsUntouchable item flag1 flag2 ancestor i; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;...also needs to be updated since it is called from EatSub 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;];&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;As shown above, both TakeSub and EatSub call additional routines that also need to be updated in the same fashion. These are AttemptToTakeObject and ObjectIsUntouchable. We won't reprint the modified versions of these two routines since they are long and the changes are minute, but the point should be made that a simple search-and-replace fixes these as well. &lt;br /&gt;&lt;br /&gt;Adding the four modified routines to your source code and putting the appropriate replace directives at the top makes the take and eat verbs available to the NPC without having to change the value of the player variable. 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;replace TakeSub; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;replace EatSub; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;replace AttemptToTakeObject; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;replace ObjectIsUntouchable; &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Also, ObjectIsUntouchable is called by numerous other verbs, and TakeSub is called by derivatives verbs. By replacing these four routines, we have also automatically made available to NPCs, all of the following routines and thus their corresponding verb forms: 
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;TakeSub &lt;br /&gt;EatSub &lt;br /&gt;PullSub &lt;br /&gt;PushSub &lt;br /&gt;TurnSub &lt;br /&gt;LockSub &lt;br /&gt;UnlockSub &lt;br /&gt;SqueezeSub &lt;br /&gt;SwitchOnSub &lt;br /&gt;SwitchOffSub &lt;br /&gt;EmptySub &lt;br /&gt;RemoveSub &lt;br /&gt;DisrobeSub &lt;br /&gt;WakeOtherSub 
&lt;/p&gt;&lt;p&gt;Since so many verbs are available to the NPC we will now drop the use of the library's "action" operators (&amp;lt;...&amp;gt; and &amp;lt;&amp;lt;...&amp;gt;&amp;gt;) in favor of the library's more generic routine, ActionPrimitive. This allows us to forego addressing the implied switch(action) statement that exists in all "reaction" routines (such as orders, life, before, etc...) and redirect all orders to the appropriate verbs with a single line of code: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt; , orders [; return ActionPrimitive();] ! replace the guard's previous orders routine &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;As we now have the ability to have the guard act for us, we can proceed with ordering him about and testing the affect of using "actor" instead of "player" in verb routines. Notice how drop, which has not yet been updated, does not function correctly: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse; background: #244061" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px"&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;guard, get apple 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;Taken. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;guard, drop apple 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;You haven't got that. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;guard, eat apple 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;You eat the apple. Not bad. &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;What's with "YOU eat the apple?" It's understandable that the guard could not drop the apple since DropSub has not been updated, but why didn't the guard eat the apple? &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Morphing Library Messages&lt;/strong&gt;
		&lt;br /&gt;&lt;br /&gt;Actually, the guard did eat the apple, but the default library message for the verb "eat" was written expecting the PC to be the only character eating. It, and many more library messages, will need to be changed to accommodate this whole new world of NPC actions. Usually, the recommend way of overloading a library message is to declare a LibraryMessages object between "Parser.h" and "Verblib.h" and implement it in the before routine. The following replacement for the "eat" message demonstrates this approach: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt; object LibraryMessages 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with before[; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;Eat: 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(lm_n==2){ 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 144pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(actor==player) print "You eat "; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 144pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;else print (The)actor," eats "; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 144pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;print (the) noun, "."; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 144pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(actor==player) print" Not bad."; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 144pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;return; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;} 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;];&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Notice that the message now changes form depending on who is performing the action: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse; background: #244061" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px"&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;guard, take apple then eat it 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;Taken. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;The guard eats the apple.&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;or, 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse; background: #244061" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px"&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;take the apple then eat it 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;Taken. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;You eat the apple. Not bad.&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;The number of library messages that need to be changed in order to implement NPC actions is somewhat excessive. Because of this, duplicating the language definition file (English.h) and making modifications there (specifying the modified file on the Inform command line or in the ICL file) may be a preferable method to instantiating a LibraryMessages object. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Initiating NPC Actions&lt;/strong&gt;
		&lt;br /&gt;&lt;br /&gt;For the examples given above, we have been calling ActionPrimitive() from within the NPC's orders routine. This has been convenient because all of the necessary library variables have already been set up for us. When the player is not issuing orders at run-time, however, we need to set these values ourselves. Additionally, there are another couple of complications that we must address: 
&lt;/p&gt;&lt;p&gt;&lt;br /&gt;1) The ActionPrimitive() routine does not honor the "before" property routines like "action notation" does (&amp;lt;&amp;lt;action&amp;gt;&amp;gt;); In order to achieve this we must make the call ourselves. &lt;br /&gt;&lt;br /&gt;2) Floating objects may not be in scope for the actor. 
&lt;/p&gt;&lt;p&gt;&lt;br /&gt;These issues can be addressed in a common routine, which seems to be most at home as part of an NPC base class: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt; class NPC 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with DoVerb[act n s svAL svActr svActn svN svS svInp1 svInp2 retval; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;svAL=actors_location; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;svActr=actor; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;svActn=action; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;svN=noun; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;svS=second; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;svInp1 = inp1; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;svInp2 = inp2; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;actors_location=parent(self); 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;actor=self; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;action=act; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;noun=n; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;second=s; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;inp1 = noun; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;inp2 = second; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;MoveFloatingObjects(); 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;retval=BeforeRoutines(); 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(retval==false) retval=ActionPrimitive(); 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;actors_location=svAL; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;actor=svActr; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;action=svActn; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;noun=svN; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;second=svS; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;inp1 = svInp1; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;inp2 = svInp2; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;MoveFloatingObjects(); 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;return retval; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;]; &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Additionally, BeforeRoutines() and AfterRoutines(), and MoveFloatingObjects() should all be modified in the same fashion as was discussed above. One exception to this "player equals actor" rule is in the call to the player's ORDERS property in the BeforeRoutines() method. This section of code should only be run if the player and actor are the same, otherwise an endless recursion results the will blow the interpreter's stack. A slightly modified BeforeRoutine() which addresses this follows: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt; [BeforeRoutines; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(GamePreRoutine()~=0) rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(actor==player &amp;amp;&amp;amp; RunRoutines(player,orders)~=0) rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(location~=0 &amp;amp;&amp;amp; RunRoutines(parent(actor),before)~=0) 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;scope_reason=REACT_BEFORE_REASON; parser_one=0; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;SearchScope(ScopeCeiling(actor),actor,0); 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;scope_reason=PARSING_REASON; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(parser_one~=0) rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(inp1&amp;gt;1 &amp;amp;&amp;amp; RunRoutines(inp1,before)~=0) rtrue; 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;rfalse; 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;];&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Assuming our NPC is derived from the NPC class, this addition will allow us to direct NPC actions from any section of code (like a controlling daemon): 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:691px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 1px; padding-left: 1px; padding-bottom: 1px; padding-right: 1px; border-top:  dashed 0.5pt; border-left:  dashed 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt; guard.DoVerb(##PutOn, apple, table); ! equates to "guard, put apple on table" &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;A Peek Inside Pandora's Box&lt;/strong&gt;
		&lt;br /&gt;&lt;br /&gt;Perhaps the reason this technique is not often seen is the number of convoluted changes that need to be made in order to implement it. At times, implementation of this technique can seem horribly daunting. &lt;br /&gt;&lt;br /&gt;The examples given above are far from complete. In addition to the excessive number of messages that must be modified, a quick scan through the verblibm.h file uncovers the following verb routines that need to be updated (only two of these were done in the above examples): 
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;InvSub &lt;br /&gt;TakeSub &lt;br /&gt;DropSub &lt;br /&gt;PutOnSub &lt;br /&gt;InsertSub &lt;br /&gt;TransferSub &lt;br /&gt;GiveSub &lt;br /&gt;ShowSub &lt;br /&gt;EnterSub &lt;br /&gt;GetOffSub &lt;br /&gt;ExitSub &lt;br /&gt;GoSub &lt;br /&gt;LookSub &lt;br /&gt;ExamineSub &lt;br /&gt;LookUnderSub &lt;br /&gt;ExitSub &lt;br /&gt;TouchSub &lt;br /&gt;WaveSub &lt;br /&gt;PushSub &lt;br /&gt;KissSub &lt;br /&gt;ThrowAtSub &lt;br /&gt;TellSub &lt;br /&gt;AskSub &lt;br /&gt;OpenSub &lt;br /&gt;WearSub &lt;br /&gt;EatSub 
&lt;/p&gt;&lt;p&gt;There are also several additional routines what are called by these verb subs that also need to be updated. Further, in many of these routines, there are references to the library variables "location" and "real_location." These need to be changed to the library variable "actors_location." &lt;br /&gt;&lt;br /&gt;Obviously a complete implementation of this technique requires major modifications to the library, but once done allows for greater flexibility with simplified, yet more powerful, coding capabilities. Additionally, since the "actor" variable and the "player" variable are normally the same, these changes are transparent. That is, the new behavior only occurs when the new functionality is used and does not affect existing code. Without calling NPC actions, games run as they always have. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;A Note on Code&lt;/strong&gt;
		&lt;br /&gt;&lt;br /&gt;The examples above were given to demonstrate this technique, but they do not necessarily represent the best way to implement it. The definition of what is "best" is left up to the reader. As a suggestion, however, rewriting messages to change form can be a convoluted and monotonous task. The print rules discussed in §1 of this article series "Pronouns on Steroids" are particularly useful. &lt;br /&gt;&lt;br /&gt;As a final point, it should be noted that a complete implementation of the techniques discussed in this article can be found at the &lt;a href="http://www.onyxring.com/orlibrary.aspx"&gt;ORLibrary&lt;/a&gt; in the entries ORNPCVerb.h, OREnglish.h, and ORNPC_doverb.h. &lt;br /&gt;&lt;br /&gt;&lt;em&gt;Special thanks go out to Stephen Robert Norris, whose input and bug fixing in the ORLibrary necessarily impacted this article.&lt;/em&gt;&lt;/p&gt;&lt;img src="http://codingmonk.com/aggbug/14.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Fisher</dc:creator>
            <guid>http://codingmonk.com/archive/2001/07/02/advanced-npc-creation-part-3-npc-actions.aspx</guid>
            <pubDate>Mon, 02 Jul 2001 05:00:00 GMT</pubDate>
            <wfw:comment>http://codingmonk.com/comments/14.aspx</wfw:comment>
            <comments>http://codingmonk.com/archive/2001/07/02/advanced-npc-creation-part-3-npc-actions.aspx#feedback</comments>
            <wfw:commentRss>http://codingmonk.com/comments/commentRss/14.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Advanced NPC Creation, Part 2c: More Advanced Knowledge and Conversation</title>
            <category>I6</category>
            <link>http://codingmonk.com/archive/2001/06/05/advanced-npc-creation-part-2c-more-advanced-knowledge-and-conversation.aspx</link>
            <description>&lt;p&gt;In the previous section we discussed various methods of sharing knowledge between characters and customizing the dialog to match a character. This section will cover additional techniques, such as topics that change content. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Morphing Topics&lt;/strong&gt;
		&lt;br /&gt;&lt;br /&gt;A common practice when developing NPCs is to have the character say random things at various points in the game. Embedded somewhere deep in whatever daemon controls the NPC can be a couple of lines of code that cause the character to speak to the player: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:658px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 59px"&gt;&lt;td valign="middle" style="border-top:  dotted 0.5pt; border-left:  dotted 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style="font-size:8pt"&gt;actor=dwarf;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;&amp;lt;tell player smalltalk&amp;gt;;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;Although it is certainly possible to create a dozen or so KnowledgeTopics, pick one at random each turn and have the NPC talk about it, a better way is to create a morphing topic. That is, a topic that prints something different each time it is used. Since this technique is best implemented with non-learnable topics, separating conversation from information need not be done: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:658px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 391px"&gt;&lt;td valign="middle" style="border-top:  dotted 0.5pt; border-left:  dotted 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;KnowledgeTopic smalltalk 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with name 'smalltalk'
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, KnownBy dwarf 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, TopicInformation[;
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;switch(random(4)){
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;1: "~There don't appear to be any other dwarves here,~ says the dwarf.  ~I'll have to notify the labor board.~";
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;2: "~I'm trying to keep my shoes clean,~ says the dwarf. ~My brothers are all envious of them.~";
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;3: "~Hi-ho!~ spouts the dwarf.";
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;4: "The dwarf scratches his bearded chin and says, ~Hmmm, I wonder where my children hid my hat.~ ";
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;}
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;]
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;Additionally, using a variation of this technique we can customize conversations to follow a specific script… &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conversation Script Topics&lt;/strong&gt;
		&lt;br /&gt;&lt;br /&gt;One of the more difficult challenges that must be faced when writing believable NPC dialog via the ASK/Tell method is getting the player to ask the right questions. In many cases there is information that needs to be conveyed to the player to further the game, yet there is no viable method of forcing him/her to make the appropriate inquiries. It is true that the occasional hint can be dropped here and there, but there are often times that a hint system just doesn't seem appropriate to the game. &lt;br /&gt;&lt;br /&gt;Having an NPC initiate conversation and thereby volunteer this information is a time-honored method of dealing with situation. In truth, this technique can be useful even if no pertinent information needs to be conveyed. People initiate conversation and volunteer trivial information as a matter of common practice. A realistic NPC should do this as well. Having an NPC follow a "conversation script" that evolves over a series of turns can help to simulate a conversation and provide pertinent information if needed. &lt;br /&gt;&lt;br /&gt;There is a caveat or two associated with this approach, though. Many developers, myself included, have implemented this technique and rendered the player helpless for a time. That is, a situation has been created where the player can do nothing except wait until the NPC is finished talking. No amount of ingenious dialog can make up for a lack of interactivity. If the only action available to the player is to type "z", the game's player immersion factor will suffer. &lt;br /&gt;&lt;br /&gt;Another thing to consider when designing a conversation script is that people generally do not repeat the same information unless asked to. In a conversation where the player actually participates, it is possible that an NPC will be asked a question earlier than he was scripted to volunteer it. Repeating the information after it has been already been told is repetitive. What is needed is a way for the NPC to remember what has already been said and to move on to the next item in the script. &lt;br /&gt;&lt;br /&gt;The "conversation script topic," a variation of morphing topics, is one of the more useful techniques in creating realistic, non-repeating dialog. It is particularly powerful because it can utilize other KnowledgeTopic objects so that the information can be both asked for and volunteered. &lt;br /&gt;&lt;br /&gt;A couple of minor modifications should be implemented to facilitate knowledge scripts. The first is a method of recording whether or not a topic has been communicated before. We can accomplish this by defining and setting an attribute. Arbitrarily, we'll call this 'hasbeentold': 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:658px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 1px"&gt;&lt;td valign="middle" style="border-top:  dotted 0.5pt; border-left:  dotted 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;attribute hasbeentold;   &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;br /&gt;The next modification we can make will ensure that the NPC doesn't "double talk" or say two things at once. This can happen when the NPC is following a script and the player asks a question. If not coded correctly, the NPC will answer the question and then continue to say whatever comes next on the topic script. Game conversation seems to more closely parallel reality if the NPC only "drives" the conversation when the player isn't talking to him. To accomplish this, we can add a property to the NPC class that records the last move he/she spoke in: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:658px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 1px"&gt;&lt;td valign="middle" style="border-top:  dotted 0.5pt; border-left:  dotted 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, LastMoveSpoken 0  !added to our NPC class&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;These values can be updated when a topic is conveyed. The TellAbout routine, in the KnowledgeTopic class, is the obvious place: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:658px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 498px"&gt;&lt;td valign="middle" style="border-top:  dotted 0.5pt; border-left:  dotted 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, TellAbout[to from; ! in our KnowledgeTopic class&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(from provides LastMoveSpoken)&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;from.LastMoveSpoken=turns+1;&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;give self HasBeenTold;&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if((self.#topicinformation/2)&amp;gt;1){&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(from provides ProcessDialog) &lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 144pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;from.ProcessDialog(to, PersonalizeTell, self, TopicInformation);&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;else{&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 144pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(from==player) print "You say, ";&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 144pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;else print (The)from, " says, ";&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 144pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;FlushDialog(self,TopicInformation,0);&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;}&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;}&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;else PrintOrRun(self,TopicInformation);&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(self has learnable) &lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt; &lt;span style="font-family:Courier New; font-size:8pt"&gt;Self.MemorizeFor(to);&lt;/span&gt;
						&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;]&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;The final new addition that we will make to the KnowledgeTopic object, which we have been developing in this article, is a routine called SayOrRecurse. The sole purpose of this routine is to facilitate a conversation script. This routine, which is called by the TellAbout routine, checks to see if the specified KnowledgeTopic has already been conveyed. If not, then it will print it and return. If so, then the TellAbout routine of the current object is called (recursively) to request the next scripted topic: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:658px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 117px"&gt;&lt;td valign="middle" style="border-top:  dotted 0.5pt; border-left:  dotted 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, SayOrRecurse [o to from; !from our KnowledgeTopic class&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(o hasnt hasbeentold) o.TellAbout(to, from);&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;else self.TellAbout(to, from);&lt;/span&gt;
						&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;]&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;Opinions vary concerning the use of recursion. Suffice it to say, misuse of this technique can cause run-time errors in the Z-Machine interpreter. Although it can be a useful addition to your conversation repertoire, use this method with care. &lt;br /&gt;&lt;br /&gt;Before creating a conversation script, an author should have a clear idea of how the conversation should flow. A design technique used by many authors is to write the entire conversation the way they would prefer it to read first. Once this has been done, the conversation can be logically separated into pieces. Almost always, these pieces of text can be classified into two categories: dialog that is the answer to a question which the player will possibly ask, and dialog that will never be asked about, and serves no purpose other than to make the NPC seem more believable. &lt;br /&gt;&lt;br /&gt;The former type, which can be inquired about, is best stored in a KnowledgeTopic of it's own. Generally, these types of dialog pieces will compromise the bulk of a conversation script. The latter type more often appears at the beginning and end of a script. Generic statements, such as variations of "hello," and "goodbye", are classified in this category. &lt;br /&gt;&lt;br /&gt;What follows is an example script object for a conversation between a doctor and the player who has just woken up in a hospital. Notice that script steps 2, 3, and 4 utilize three other KnowledgeTopics and so will be brought up, even if not directly asked about by the player. 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:658px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 1082px"&gt;&lt;td valign="middle" style="border-top:  dotted 0.5pt; border-left:  dotted 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;KnowledgeTopic DocScript_t
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with     count     0, KnownBy doctor
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, TellAbout[towho fromwho;
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;self.count=self.count+1;
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;switch(self.count) {&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;1: print "^~How are you feeling, Mr. Valentine?  I'm pleased to see you've awakened,~ the man says to you. ";
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;2: self.SayOrRecurse(doc_who_t,towho, fromwho);
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;3: self.SayOrRecurse(doc_me_t, towho, fromwho);
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;4: self.SayOrRecurse(hosp_where_t, towho,fromwho);
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;5: print "~Okay then,~ says the doctor as he opens the door.  ~If you have anymore questions, feel free to buzz the nurse.~  He leaves and closes the door behind him.";
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;self.TellAbout=NULL;
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;}
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;];
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;KnowledgeTopic doc_who_t
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with name 'him' 'himself' 'man' 'doc' 'doctor' 'who'
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, KnownBy doctor
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, query  "^~So who are you?~ I asked the man. "
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, TopicInformation "^~My name is Doctor Harris.  I'm the resident Nuerological specialist.~ ^^~Nuerological.~ You repeat, then touch your head probingly. No bandage.^^The doctor nods. "
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;KnowledgeTopic doc_me_t
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with name 'myself' 'self' 'me' 'head' 'damage' 'condition'
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, KnownBy doctor
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, query "^~So what's my condition, Doc?~ You ask."
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, TopicInformation "^^~You're the talk of the hospital right now,~ he replies. ~You've been comatose for several weeks. CAT scans showed extreme cerebral dysfunction. To be frank, the prognosis was bleak.^^~This morning, for no apparent reason, monitors registered a return to normal brain activity. Further examination showed burned tissue and broken ribs healed. I've never seen anything like it before.~^^Cerebral dysfunction... You think about that for a moment when it suddenly dawns on you that you cannot remember anything about yourself, including your own name!"
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;KnowledgeTopic hosp_where_t
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with name 'where' 'hospital' 'location'
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, KnownBy doctor
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, query "^~So where am I?~ ,You ask the doctor. "
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, TopicInformation "^~You're at Saint Augustine Hospital.~^Saint Augustine. You don't recognize the name. "
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;Additionally, a believable NPC will have a collection of additional topics that are not volunteered, but are clarifications of statements made in the script. This NPC will be able to answer questions the player may have in the course of the conversation but will not volunteer this information unless directly asked about it: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:658px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 447px"&gt;&lt;td valign="middle" style="border-top:  dotted 0.5pt; border-left:  dotted 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;KnowledgeTopic doc_amnesia_t 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with name 'memory' 'amnesia'
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, KnownBy doctor
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, query "^~So could my memory be affected?~ You ask."
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, TopicInformation "^^~Certainly,~ he said.  ~Without a doubt, the explosion, and events immediately preceding and following it would be unclear to you. That's normal.  There may even be more substantial memory loss.~"
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;KnowledgeTopic explosion_t 
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with name 'explosion'
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, KnownBy doctor
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, query "^~What happened? You said I was in an explosion? ~"
&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, TopicInformation "^^A sad look comes across the doctor's face.  ~I'm afraid that I don't know many of the details behind what happened to you. I only know that there was an explosion of some kind.  I have no information as to the condition of your family.~^^You watch his eyes as he says this to you. For reasons you don't know, you concentrate upon pupils as they dilate. In the back of your head, some forgotten memory tells you that this means he is lying. "
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;Now that we have a workable script, we need an NPC capable of driving the conversation: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:658px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 204px"&gt;&lt;td valign="middle" style="border-top:  dotted 0.5pt; border-left:  dotted 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;NPC -&amp;gt; doctor "man" &lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;with name 'doc' 'doctor' 'harris' 'man'   &lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, description "The man is dressed in a white coat.  He appears to be a doctor."&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;, each_turn[; if(self.LastMoveSpoken==turns) return;&lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 72pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;if(DocScript_t provides TellAbout) &lt;/span&gt;
						&lt;/p&gt;&lt;p style="margin-left: 108pt"&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;DocScript_t.TellAbout(player,self);&lt;/span&gt;
						&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:8pt"&gt;];&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;This simple NPC will converse with the player each turn about our script object. The conversation can happen in several different ways now. One possible play out of the script follows: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse; background: #17365d" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:689px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td valign="middle" style="padding-top: 19px; padding-left: 5px; padding-bottom: 19px; padding-right: 5px"&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"How are you feeling, Mr. Valentine? I'm pleased to see you've awakened," the man says to you. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&lt;strong&gt;&amp;gt;x man 
&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;The man is dressed in a white coat. He appears to be a doctor.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"My name is Doctor Harris. I'm the resident Neurological specialist."   
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"Neurological." You repeat, and then touch your head probingly. No bandage.  
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;The doctor nods. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&lt;strong&gt;&amp;gt;ask doc about head
&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"So what's my condition, Doc?" You ask.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"You're the talk of the hospital right now," he replies. "You've been comatose for several weeks. CAT scans showed extreme cerebral dysfunction. To be frank, the prognosis was bleak.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"This morning, for no apparent reason, monitors registered a return to normal brain activity. Further examination showed burned tissue and broken ribs healed. I've never seen anything like it before."
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;Cerebral dysfunction... You think about that for a moment when it suddenly dawns on you that you cannot remember anything about yourself, including your own name!
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&lt;strong&gt;&amp;gt;ask doc about hospital
&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"So where am I?", You ask the doctor. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"You're at Saint Augustine Hospital."
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;Saint Augustine. You don't recognize the name. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&lt;strong&gt;&amp;gt;ask doc about memory
&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"So could my memory be affected?" You ask.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"Certainly," he said. "Without a doubt, the explosion, and events immediately preceding and following it would be unclear to you. That's  normal. There may even be more substantial memory loss."
&lt;/span&gt;&lt;/p&gt;&lt;p&gt; 
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&lt;strong&gt;&amp;gt;ask doc about explosion
&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"What happened? You said I was in an explosion?"
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;A sad look comes across the doctor's face. "I'm afraid that I don't know many of the details behind what happened to you. I only know that there was an explosion of some kind. I have no information as to the condition of your family."
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;You watch his eyes as he says this to you. For reasons you don't know, you concentrate upon his pupils as they dilate. In the back of your head, some forgotten memory tells you this means he is lying.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;  
 &lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;&amp;gt;z
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;Time passes.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:white; font-family:Courier New; font-size:8pt"&gt;"Okay then," says the doctor as he opens the door. "If you have anymore questions, feel free to buzz the nurse."  He leaves and closes the door behind him.&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Of course this is just a basic example, but notice that the script adapts and skips over topics already asked about by the player. This technique has the advantage of ensuring that the player gets information, even if he does not think to ask the appropriate question, but also adapts to a player's questions, ensuring a more realistic conversation. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Inanimate Knowledge Transfer&lt;/strong&gt;
		&lt;br /&gt;&lt;br /&gt;It was mentioned above that characters are not the only objects that can utilize the knowledge objects. Any book, such as "Waldecks's Mayan dictionary" from the Inform Designer's Manual, or the ever-popular spell book is an ideal candidate for an inanimate object housing KnowledgeTopics. The consult verb should be extended much as the tell verb was: 
&lt;/p&gt;&lt;div style="margin-left: 36pt"&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:658px" /&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 88px"&gt;&lt;td valign="middle" style="border-top:  dotted 0.5pt; border-left:  dotted 0.5pt; border-bottom:  solid black 1.5pt; border-right:  solid black 1.5pt"&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style="font-size:8pt"&gt;[ConsultTopicSub; second.TellAbout(actor,noun); ]; 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style="font-size:8pt"&gt;extend "consult" first * noun 'about' scope=TopicInTarget-&amp;gt; ConsultTopic   
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&l