Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

QUiz script help

Mohd Belgar
Registered User
Join date: 1 Oct 2008
Posts: 14
10-05-2009 16:41
Hello Guys,

I want to create a multiple choice quiz but I need head start tips what functions, events..ect is best to use.

the script should function as the following:

for example:

Question 1

option 1
option 2
option 3
option 4

after user choice switch to question 2 then 3,4,5...ect

at the end give mark
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
10-05-2009 23:20
The first method that comes to mind is to use a notecard to store the questions and answers. The notecard would be formatted with the question on one line, followed by the four answers, one per line. The first answer would always be the correct answer, the rest decoys:

Question
correct answer
wrong answer
wrong answer
wrong answer
Question
correct answer
wrong answer
wrong answer
wrong answer
etc.

Read the notecard one set of question/answers at a time, wait for the user to answer, then read the next set of question/answers. Each pass, the system will chat something like, "Generating Question..." as it reads. Within the dataserver() event , the question will be stored as a string, the first answer will also be stored as a string as well as added to a list of all answers. When finished reading the data, the answers list will be scrambled using llListRandomize(), followed by a search for the correct answer to store that index using llListFindList().

To chat the question, build a string starting with the question. Then, use a 4-step loop to build the answers portion of the string using the loop index (1 - 4). Each time around the loop, add "\n(" + (string)index + ";)" + llList2String(answers, index - 1).

Once the user sees the question/answers, they'll type the number corresponding to the right answer. The listen() event would compare the user's number to the known correct answer index. If right, add to the correct total.
Mohd Belgar
Registered User
Join date: 1 Oct 2008
Posts: 14
10-08-2009 08:04
Hi DoteDote Edison

Appreciate the help and the suggestion..

I liked your idea and started scribting but as Unexperiance scribter I got stuck early, I did create the note card with only 3 question for a start... and done dataserver() part every thing was fine and all the question where generated when I click on the item but when I tried to scramble using llListRandomize() I guess that I did not know how to make it look inside the notecrad to scramble the question.

look at the code:

CODE

list gOneCard;
key kQuery;
integer iLine = 0;
string gsCardOneName = "One";
default {

touch_start(integer total_number) {
llSay(0, "Reading notecard...");
kQuery = llGetNotecardLine("One", iLine);
list shuffled = llListRandomize(gOneCard, 1);
llOwnerSay(llList2CSV(shuffled));

}

dataserver(key query_id, string data) {

if (query_id == kQuery) { // were we called to work on "My Notecard"?
// this is a line of our notecard
if (data == EOF) {

llSay(0, "No more lines in notecard, read " + (string)iLine + " lines.");

} else {

llSay(0, "Line " + (string)iLine + ": " + data); // data has the current line from this notecard

//request next line
iLine++; // increment line count
kQuery = llGetNotecardLine("One", iLine); // read another line when you can

{

list list_random = llListRandomize(gsCardOneName, 2);
list list_random = llListRandomize(gsCardOneName, 3);

}

}
}
}
}


so any suggestion ?
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
10-08-2009 18:44
Last year I wrote something called MultiMenu and created an extensive tutorial for it, including an example for a quiz. I eventually stopped working with it because it was so slow and the learning curve wasn't where I wanted it to be (I had visions of ordinary users being able to develop dialogs with it but it was still a pretty hard slog for most people). Could be worth a shot, though. You should be able to find it searching the forums. If not, drop me a line in-world and I'll give you a copy.
Rebekka Revnik
Registered User
Join date: 26 Mar 2008
Posts: 18
10-09-2009 02:05
Here's something to play with.
CODE
integer STRIDE = 4;			// one question and three answers
string NCNAME = "quiz"; // name of the nc
key NCid; // id of the request
integer NCLine; // current nc line
list Items; // questions and answers

string Question; // the question
list Answers; // the answers
string Correct; // correct answer

Init()
{
Items = [];
if(llGetInventoryType(NCNAME) != INVENTORY_NONE)
{
llSay(0, "Reading nc");
NCLine = 0;
NCid = llGetNotecardLine(NCNAME, NCLine++);
} else llSay(0, "No nc found.");

}

GetQuestion()
{
if(llGetListLength(Items) < STRIDE) return;
integer Max = llGetListLength(Items) / STRIDE;
integer x = (integer)llFrand(Max);
integer p = x * STRIDE;
Question = llList2String(Items, p);
Correct = llList2String(Items, p + 1);
Answers = llListRandomize(llList2List(Items, p + 1, p + 3), 1);
}

default
{
state_entry()
{
Init();
}
on_rez(integer start_param)
{
Init();
}
touch_start(integer total_number)
{
GetQuestion();
llSay(0, "The Question is: " + Question);
llSay(0, "These are the answers:");
integer i;
for(i = 0; i < STRIDE-1; i++) llSay(0, (string)(i + 1) + ". " + llList2String(Answers, i));
llSay(0, "The correct answer is: " + Correct);
}
dataserver(key requested, string data)
{
if(requested == NCid)
{
if(data != EOF)
{
Items += [data];
NCid = llGetNotecardLine(NCNAME, NCLine++);
} else llSay(0, "Ready.");
}
}
}