Jump to content

Help needed to make random questions appear in dialog box


phelpsa
 Share

You are about to reply to a thread that has been inactive for 4502 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi, I am very novice at scripting and would really be greatful for a little help.

 

I have started a script that works well, but i want to modify it to ask random questions in a dialog box, instead of just the 1 question at a time that it asks now.

 

Any help would be awesome, and thanks in advance!!

 

Here is what i have now.

 

list cStudents;
list submitted = [];
integer listener;

// make this the question the students will see
string question = "Here is question number 1, and this would be question number 2, etc..";
// make admin the teachers name
key admin = "avatar name";
// make emailAd the teacher's email
string emailAd = "test@gmail.com";
// this will appear in the
string course = "Test Class";


emailList() {
    string msg;
    msg = llDumpList2String(submitted, "\n\n");
    llEmail(emailAd, "Results of "+course, msg);
}
default
{
    state_entry()
    {
    }
   

    touch_start(integer total_number)
    {
        key clicker = llDetectedKey(0);
        if(llListFindList(cStudents, [clicker]) != -1) {
            llInstantMessage(clicker, "You've already submitted");
            return;
        }
        if(llKey2Name(clicker) == admin) {
            llInstantMessage(clicker, "Results sent from this picture");
            emailList();
            return;
        }
        integer channel = (integer)llFrand(1000.0);
        listener = llListen(channel, "", clicker, "");
        llTextBox(llDetectedKey(0), question, channel);
    }
    listen(integer channel, string name, key id, string message) {
        submitted += [(name + ":\n" + message)];
        llListenRemove(listener);
        llInstantMessage(id, "Recorded \"" + message + "\" as your answer");
        cStudents += [id];
    }
}


Link to comment
Share on other sites

How to go about it depends on a number of things that you haven't stated

  1. How many questions would you like to have in your system? If the number isa no all too big, they can simply be stored in a list variable
  2. You say you want a dialog for ansering - is there the same number of anser options for all questions? Is it just "Yes" and "No"?
  3. Would you want the editing of answers and questions to be done outside the script?
Link to comment
Share on other sites

Thanks,

 

There will be less than 10 very short questions, all will be open ended and can be answered in less than 250 characters.

And it for the questions and answers its ok if it stays in the script.  As of now the answers are emailed to 1 recipient.

 

Thanks

Link to comment
Share on other sites

Well, in this case I would use a notecard to store the questions. The script would (at least triggered by the state_entry and the changed event (hfor inventory chages)) first read the notecard using llGetNotecardLine and the dataserver event - look at the examoles on the pages I linked - I guess they will help you understand to work out how notecard reading work. Store the result of the notecard reading in a list - one question as a list entry.

On the touch event, you could generate a random integer between 0 and the length of your list - 1 - how to generate such a nunmer, look here (look at the examples). Now get the random question by using your random number as thewindex in llList2String - the rest is like in your script. You may want to store the current question (the index or the question) in a global variable, so you can email it along with the answer.

I hope that shows you the direction.

If you get stuck, come back!

Link to comment
Share on other sites

Make a notecard with your questions - on question per line (line here means that there is to be a line break - not the wrapping if the line is to long to be shown as a single line) and name it 'questions' - put it in the prim along with the script below and it should do the trick

list cStudents;list submitted = [];integer listener;// make this the question the students will seestring question = "Here is question number 1, and this would be question number 2, etc..";// make admin the teachers namekey admin = "avatar name";// make emailAd the teacher's emailstring emailAd = "test@gmail.com";// this will appear in thestring course = "Test Class";///////////////////////variables needed for the ncstring gsNC = "questions"; //the nane of the NC in the inventoryinteger giLines; //te counter for reading the lineskey gkQuery; //key of the querylist glQuestions = []; //list of questionsstring gsCurrQuestion; //current questionemailList() {    string msg;    msg = llDumpList2String(submitted, "\n\n");    llEmail(emailAd, "Results of "+course, msg);}default{    state_entry()    {    	gkQuery = llGetNotecardLine(gsNC, giLines = 0);    }       touch_start(integer total_number)    {        key clicker = llDetectedKey(0);        if(llListFindList(cStudents, [clicker]) != -1) {            llInstantMessage(clicker, "You've already submitted");            return;        }        if(llKey2Name(clicker) == admin) {            llInstantMessage(clicker, "Results sent from this picture");            emailList();            return;        }        integer randInt = (integer)( llFrand( llGetListLength(glQuestions)));        integer channel = (integer)llFrand(1000.0);        listener = llListen(channel, "", clicker, "");        gsCurrQuestion = llList2String(glQuestions, randInt);        llTextBox(llDetectedKey(0), gsCurrQuestion, channel);    }    listen(integer channel, string name, key id, string message) {        submitted += [(name + ":\n" + message + " for question: ") + gsCurrQuestion];        llListenRemove(listener);        llInstantMessage(id, "Recorded \"" + message + "\" as your answer");        cStudents += [id];    }        dataserver(key queryid, string data) {    	if (queryid == gkQuery) {    		if (data == EOF) { //we have reached the end of the NC    			if (!llGetListLength(glQuestions)) {    				state not_running; //if the script couldn't find a question, do nothing    			}    		} else if (llStringTrim(data, STRING_TRIM) != "") { // we pass empty ines    			glQuestions += [data]; //add the line to the list    		}     		gkQuery = llGetNotecardLine(gsNC, ++giLines); //read the next line    	}    }    changed(integer change) {		if(change & CHANGED_REGION) {			llResetScript(); //start the script again if the content changes		}	}}state not_running {	state_entry() {		llOwnerSay("No questions found");	}		changed(integer change) {		if(change & CHANGED_REGION) {			state default; //start the script again if the content changes		}	}}

 

Link to comment
Share on other sites

This looks very good!  thank you.

 

I made the note card with questions.  But I get a error called lltextbox: must supply a message.

 

My notecard looks as follows.

 

-this is question number 1.

-this is question number 2.

 

 

Thanks,

Link to comment
Share on other sites

Ok, sorry but i have one more obstacle..

 

After a person submits the response for one question, the text box says they have submitted.  But what if they want to click the object again hoping to get another question and asnwer it?  As of now when i try it, one avatar can only answer one question after hitting submit.

 

Thanks

Link to comment
Share on other sites

The LSL Scripting forum is a place for scripters to share insights or help resolve puzzles in their scripts. If you are writing your own LSL script and need some help getting over a confusing spot, therefore, you have come to the right spot.  If you are looking for a freebie script or want to hire a scripter to write something for you, however, you should be posting in the Wanted forum or the Inworld Employment forum. 

I'm not scolding.... just sayin'...... :smileywink:

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4502 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...