Answere Machine

De DigiWiki.

This script, for all intents and purposes, is an answering machine.

integer questionNumber;
list questions;
string longname;
string shortname;
key questioner;
key speaker;
 
checkForQuestions()
{
    //if the question list is empty
    if(questions == []){
        //turn red
        llSetColor(<1,0,0>,ALL_SIDES);
        //reset question count
        questionNumber = 0;
    //if not
    }else{
        //turn green
        llSetColor(<0,1,0>,ALL_SIDES);
    }
}
 
default
{
    //say how to use it
    on_rez(integer start_param)
    {
        checkForQuestions();
        llSay(0,"Hi!");
        llSay(0,"Click on me to record a question.");
    }
    //listen on channel 7 (to set speaker)
    state_entry()
    {
        checkForQuestions();
        llListen(7,"",NULL_KEY,"setup");
    }
 
    //setup mode
    listen(integer channel, string name, key id, string message)
    {
        llSay(0,"Setup mode");
        state setup;
    }
 
    touch_start(integer total_number)
    {
        integer sname_end;
        //if the speaker touches it, read off the questions
        if(llDetectedKey(0) == speaker){
            //if there are no questions
            if(questions == []){
                llSay(0,"There are no questions");
            }else{
                //get first 2 list entries (question + name)
                string currentQuestion = llList2String(questions,0);
                string currentName = llList2String(questions,1);
                questionNumber++;
                llSay(0,"Question " +(string)questionNumber+ " from " +currentName+ ": " +currentQuestion);
                //delete first 2 list entries
                questions = llDeleteSubList(questions,0,1);
                //turn red if necessary
                checkForQuestions();
            }
        }else{
            //if someone else touches it, grab their name and go into listening state
            longname = llDetectedName(0);
            sname_end = llSubStringIndex(longname, " ");
            if (sname_end <= 0)
                shortname = longname;
            else
                shortname = llGetSubString(longname, 0, sname_end-1);
            llInstantMessage(llDetectedKey(0),"Type your question on channel 6, " +shortname);
            questioner = llDetectedKey(0);
            state listenToDudes;
        }
    }
}
 
//listening state
state listenToDudes
{
    state_entry()
    {
        //listen on channel 6
        llListen(6, "", NULL_KEY, "");
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if(message == "cancel"){
            llInstantMessage(questioner,"Cancelled");
            state default;
        }else{
            //when someone speaks on channel 6, add their question and name to the list
            questions += [message, shortname];
            //tell them their message has been recorded
            llInstantMessage(questioner,"Message recorded");
            //turn green
            checkForQuestions();
            //return to default state
            state default;
        }
    }
 
    //if someone else tries to record a question, tell them to wait
    touch_start(integer total_number)
    {
        llInstantMessage(llDetectedKey(0),"Wait a tick, someone else is asking a question");
    }
}
 
state setup
{
    state_entry()
    {
        llListen(7,"",NULL_KEY,"");
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if(message == "reset"){
            llSay(0,"Script reset");
            llResetScript();
        }else if(message == "speaker"){
            speaker = id;
            llSay(0,"Speaker is " +name);
        }else if(message == "no speaker"){
            speaker = "";
            llSay(0,"no speaker");
        }else if(message == "exit"){
            llSay(0,"Exiting setup");
            state default;
        }
    }
}

Purpose

In a lecture, people may want to ask questions but not want to interrupt. This script listens to you on a private channel (so it is silent on public chat) and stores your question. At the end of the lecture, the speaker can click on the object and it will regurgitate the questions from first to last.

How to use it

Stick it in an object. The object should appear red; this indicates there are no questions stored.

First you need to set yourself as the 'speaker' - so when you click on it, it will read out the questions.

  • Type '/7 setup' to enter setup. From here you can type:
    • '/7 speaker' - to set yourself as the speaker
    • '/7 no speaker' - to un-set yourself as the speaker (for testing purposes)
    • '/7 reset' - (for if it screws up)
  • Then type '/7 exit' to exit setup.

Anyone except the speaker can now ask a question: click on the object, and it will tell you to type the question on channel 6.

  • Type '/6 ' followed by your question
  • To cancel, type '/6 cancel'

The object will say 'Message stored' and will now turn green. You can now ask another question. If someone else is asking a question when you click on it, you will be politely asked to wait.

At any time, the speaker may click the object and it will return the questions one by one, in a first-in first-out order. When it turns red, there are no questions left.

Outils personnels
  • Cette page a été consultée 607 fois.
donate
Google Ads