Monday, 23 March 2015

The Oracle

Here's a bit of silliness.

Place this script in a prim on a region where NPCs and OSSL are enabled, then touch.

It works on the infinite monkeys theorem...if you hang around long enough the oracle will eventually say something earth shatteringly important. You might need a few pots of coffee while waiting, though.

#########################
THE SCRIPT
#########################


integer maxWordsPerSentence=15; // how many words to say in the longest sentence
integer maxLettersPerWord=12;   // maximum number of letters in a word
float talkFrequency=5.0;       // how often to say something

list char=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
list caps=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
list punct=[".","!","?"];
key npc;

saySomething()
{
    integer wordsToSay=llCeil(llFrand((float)maxWordsPerSentence));
    integer word;
    string sentence;
    while(word<wordsToSay)
    {
        string thisWord;
        integer thisWordLength=llCeil(llFrand((float)maxLettersPerWord));
        integer letter;
        while (letter<thisWordLength)
        {
            if (!word)
            {
                if (!letter) thisWord+=llList2String(caps,llRound(llFrand((float)llGetListLength(caps))));
                else thisWord+=llList2String(char,llRound(llFrand((float)llGetListLength(char))));
            }
            else
            {
                if (!letter) thisWord+=" ";
                thisWord+=llList2String(char,llRound(llFrand((float)llGetListLength(char))));
            }
            letter++;
        }
        sentence+=thisWord;
        word++;
    }
    sentence+=llList2String(punct,llRound(llFrand((float)llGetListLength(punct))));
    osNpcSay(npc,sentence);
}

default
{
    state_entry()
    {
        npc=NULL_KEY;
    }
    touch_start(integer num)
    {
        if (npc==NULL_KEY)
        {
            npc=osNpcCreate("The","Oracle",llDetectedPos(0)+<1.0,0,0>,llDetectedKey(0));
            llSetTimerEvent(talkFrequency);
            osNpcSay(npc,"Heed the words of the oracle!");
        }
        else
        {
            osNpcSay(npc,"The oracle has spoken");
            osNpcRemove(npc);
            npc=NULL_KEY;
            llSetTimerEvent(0.0);
        }
    }
    timer()
    {
        saySomething();
    }      
}