Pages

Tuesday, July 6, 2010

"Voice" activated agents

Wooow life has been busy lately. Between running the CCSF Surveys and having some friends in town, on top of work, keeping the house clean, and all that fun stuff, I haven't had a whole lot of time for Creaturely enjoyments. Regardless, I figured I would make a post about something I have been fiddling with the last few days.

As a few of you may know, I can't sprite. As fewer of you may know, I don't -like- to sprite. Okay, I can enjoy spriting things when the sprite is the charm of the agent, like a critter or a plant, but when I'm coding something utilitarian, like a control panel or a machine, spriting is just this annoying necessity that I have to do to make my code accessible to the majority. As such, I generally seek to find ways around it. Shortcut keys are one example. But lately I've been experimenting with "voice" activation, that is, simple commands are typed into the hand's speech bubble to trigger certain scripts. I'll share what I've found so far-- it's fairly simple if you understand some CAOS basics.

You'll want to set this on short timer script-- shorter than it takes for speech bubbles to possibly disappear unseen.

enum 1 2 9

1 2 9 is the classifier for all the speech bubbles, including those made by creatures. This script is essentially going to search every speech bubble in the world for a certain trigger phrase.

doif ov80 ne 1
setv ov80 1

When the script is running possibly several times within a speech bubble's life, it's very possible that it will search the same bubble more than once, and thus produce the effects more than once. To stop this from happening we want to "mark" each speech bubble that we search by changing an ov (I use 80, but you can really use anything the speech bubble doesn't already use) to reflect this. If the bubble has been marked, the script passes over and ignores it, if it is unmarked, the script marks it and carries on with the script.

part 1

part 1 is the text part of the compound agent that is the speech bubble, so the script needs to focus on that to see what's inside.

sets ov82 ptxt

And in just about five lines of code, you have the text of a speech bubble stored in ov82! But it's not finished yet, because when you're searching the bubbles for a trigger word, the searches are case sensitive, so to prevent problems with that you'll want to convert it to all lower case:

sets ov82 lowa ov82

Better. Now you can set your trigger scripts here. Most commonly you would do something like:

doif ov82 = "cheese"
*insert whatever script the word "cheese" will trigger
endi

but the trigger word doesn't have to match the speech exactly, you can also used a SINS command to search inside the text instead of matching it directly.

doif sins ov82 1 "cheese" ne -1
*insert cheesy script
endi

This option will trigger the script if your speech bubble contains the word "cheese" at all, so if you said "I love cheese" or "This cheese is green" the script would trigger. You can actually make some very complex commands if you use SUBS to break up the strings, too.

Make sure you close out your script with endi and next!

It's worth reminding you that this does read all speech bubbles including those of creatures, so you could do something like search the text for the phrase "hungry for starch" and cause the script to get the location of the bubble and go drop some seeds there (though you would probably want use the catalogue tags instead of directly searching for the word/phrase to keep it compatible with non-english versions of creatures).

The upside to these command-activated agents is that they require no sprites and no items to clutter your screen or keep track of. I guess the downside would be that if there were a lot of commands involved, people would be more apt to forget them all.

What do you guys think? Would you use a "voice" activated agent or do you prefer to push a button?