Sunday, November 6, 2011

Magic Words Template

First, I would like to say that today would mark the 23rd birthday of my favorite cat, were he still living. Even though he passed several years ago, I always remember him on his birthday. Happy birthday, Kitty-Witty; I hope you are having a lovely party in cat-heaven.


When I first brainstormed the notion of an agent that responded to speech-bubble commands, I remember one of my priorities was to make it easily expandable. I didn't want to have to recode my whole script every time I wanted to add a new command. So the system I came up with allowed the core agent to scan for "plugin" agents for matching words or phrases, and then execute the script within the plugin agent when a match is found.

I tried to set it up so it would be as easy as possible to write a plugin script so that any coder who wanted to could easily write their own speech-bubble activated commands without having to rewrite the core agent.  I hope I succeeded, but you guys will be the judge of that.

You can download the working template here for detailed information and examples, but the process is really rather simple:

First create a simple agent with a blank sprite file and classifier 1 200 X. X being of course, a number of your choosing, one that doesn't overlap with someone elses, as with all classifiers. The important thing here is that the family is 1 and the genus is 200, since these are the classifiers that the core agent scans for.

Then, define name variables for the agent:
"magic_word_count" -- integer, the number of words/phrases you're going to address in this agent.
"magic_word_#" -- string, the word/phrase that must be entered to activate the script
"magic_word_help_#" -- string, the text that shows up listing the word/phrase and what it does in the help window (the one that pops up when you type "help" in the speech bubble).

You need to define as many magic_word and magic_word_help variables as defined in the magic_word_count variable. So for example, if "magic_word_count" is set to 2, you will need to define "magic_word_1" "magic_word_2" "magic_word_help_1" and "magic_word_help_2"

From there all you have to do is write your scripts. When the word or phrase defined in magic_word_1 is triggered, the agent will run script 1001,  magic_word_2 will trigger 1002, and so on, so write scripts accordingly.

Here's a tip-- if you define magic_word_1 as "potato" the script will obviously trigger if you type "potato" in the speech bubble-- however, if you define magic_word_1 as "_potato" the script will trigger if you type any phrase containing the word "potato" such as "eat potato" or "potatoes are awesome." The contents of the speech bubble are then sent to the script within _p1_, allowing for more complex commands.

More details can be found in the aforementioned template cosfile, but that's the basics of it. I hope you caos-inclined creature-people can play around with it and put lots of interesting and useful commands at our fingertips!

No comments:

Post a Comment