Change font size
It is currently Thu Aug 13, 2020 6:29 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 5 posts ]
Author Message
 Post subject: randomize questions in quiz without repeating same question
PostPosted: Sun Dec 08, 2019 4:15 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi again!
I've got a script using random questions in a multiple choice dialog quiz (largely provided by djphil).
It asks the user questions in a random order.

What I would like to do is make sure each question is only asked once and not several times.
I haven't been able to understand how this is done in the script.
Maybe you could help me and explain to me how it works?

Thank you very much in advance.
Here is the script:

{L_CODE}:
integer gameover;
key player;

integer counter;
list quiz = [
// question                     answer  picks (buttons) the pipe | is the delimiter
   "\n\nWas heißt auf Englisch \n\n\n'weil'", "because", "now|also|but|because",
   "\n\nWas heißt auf Englisch \n\n\n'obwohl'", "although", "although|now|but|because",
   "\n\nWas heißt auf Englisch \n\n\n'auch'", "also",  "although|also|but|because",
   "\n\nWas heißt auf Englisch \n\n\n'aber'", "but",  "although|now|but|because",
   "\n\nWas heißt auf Englisch \n\n\n'jetzt'", "now",  "although|also|now|because",
   "\n\nWas heißt auf Englisch \n\n\n'heute'", "today",  "yesterday|tomorrow|now|today",
   "\n\nWas heißt auf Englisch \n\n\n'morgen'", "tomorrow",  "yesterday|tomorrow|now|today",
   "\n\nWas heißt auf Englisch \n\n\n'gestern'", "yesterday",  "yesterday|tomorrow|now|today",
   "\n\nWas heißt auf Englisch \n\n\n'immer'", "always",  "always|also|although|again",
   "\n\nWas heißt auf Englisch \n\n\n'wieder'", "again",  "always|also|although|again"
];

integer CHANNEL = -202;

integer index;
integer count;
string answer;

default
{
state_entry()
{
    count = llGetListLength(quiz) / 3; //<-- This is part of the randomization.
    llListen(CHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users)
}
touch_start(integer num)
{
   key player = llDetectedKey(0);
   if (gameover)
    {
        gameover = FALSE;
    }
   
    if (llDetectedKey(0) == player) // ignore touches from people not the player
    {
   index = (index + 1 + (integer)llFrand(count)) % count * 3; //<-- This is part of the randomization.
   // get the question
   string question = llList2String(quiz, index);
   answer = llList2String(quiz, index + 1);   
   string picks = llList2String(quiz, index + 2);
   list buttons = llParseString2List(picks, ["|"], []);
   llSetTimerEvent(60.0);
   llDialog(llDetectedKey(0), question, buttons, CHANNEL);
   }
}   
   
   timer()
{
    gameover = TRUE;
    llSay(0, "\n\nGame Over!\n\n\n");
    llResetScript();
}   

listen(integer channel, string name, key id, string message)
{
   if (message == answer)
   {
    llSay(0, "\n\nThat's correct, "+name+".\n\n\n");
   index = (index + 1 + (integer)llFrand(count)) % count * 3; //<-- This is part of the randomization.
   string question = llList2String(quiz, index);
   answer = llList2String(quiz, index + 1);   
   string picks = llList2String(quiz, index + 2);
   list buttons = llParseString2List(picks, ["|"], []);
   
   counter ++;
         if(counter < 10)
        {
            llDialog(id, question, buttons, CHANNEL);
        }
        if(counter == 10)
        {
            gameover = TRUE;
            llDialog( id, "Congratulations, "+id+"!  You won!\n\n\n", ["OK"], CHANNEL);
            llPlaySound("ed124764-705d-d497-167a-182cd9fa2e6c ",1.0);
            llResetScript();
        }
   }
   
   else
   {
    llSay(0, "\n\nYou lose, "+name+".\n\nStart again.\n\n\n");
    llResetScript();
   }
}
}


Top
 Profile  
 
 Post subject: Re: randomize questions in quiz without repeating same question
PostPosted: Mon Dec 09, 2019 12:40 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 291
Location: Belgium / Brussels
Hi, there are many ways to do this, here's a way ;)

1) you can gradually delete the questions already asked from the initial list.

Fonctional exemple:
{L_CODE}:
list questions = ["a", "b", "c", "d", "e"];

default
{
    state_entry()
    {
        llOwnerSay("Initialisation ...");
    }
   
    touch_start(integer number)
    {
        integer len = llGetListLength(questions);
        if (len <= 0) llResetScript();
        integer random = llRound(llFrand(len)) - 1;
        string question = llList2String(questions, random);
        questions = llDeleteSubList(questions, random, random);
        llOwnerSay("Question = " + question);
    }
}


2) What you do for ignore keys from people not the player has no effect
{L_CODE}:
key player = llDetectedKey (0);
if (llDetectedKey (0) == player)
{
     ....
}

You must do like this:
{L_CODE}:
key player;

default
{
    state_entry()
    {
        llOwnerSay("Initialisation ...");
    }
   
    touch_start(integer number)
    {
        player = llDetectedKey(0);
        state play;
    }
}

state play
{
    touch_start(integer number)
    {
        key user = llDetectedKey(0);

        if (user == player)
        {
            llRegionSayTo(user, PUBLIC_CHANNEL, "Ok " + llKey2Name(player) + " you are the current player, we can play ...");
        }
        else llRegionSayTo(user, PUBLIC_CHANNEL, "Sorry " + llKey2Name(user) + " the game is already used by " + llKey2Name(player));
    }
}


3) You open a listening from the start ... but there is no player at this time ... so why already open the listening?
You have to open the listening only when the game starts (with the valid player) and you have to close it when the game is over.

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: randomize questions in quiz without repeating same question
PostPosted: Mon Dec 09, 2019 12:58 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi again!
Thank you so much for your advice.
I don't have time to check it out right now, but I'll do so as soon as I can in the next days and come back here again to give you some feedback.
Thanks again, mate! :)


Top
 Profile  
 
 Post subject: Re: randomize questions in quiz without repeating same question
PostPosted: Sun Dec 15, 2019 12:21 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi again!
Thank you very much for your help.
I ended up using a slightly different method.

I haven't had time to integrate your suggestion no2, but I'll do that later.
I'm posting the script below.

The script does the following:

With each correct answer a part of a transparent linkset is made visible, which serves as a victory podium.
The linkset consists of 10 transparent childprims,
and one non-transparent childprim as starting button (childprim 11).

Once all childprims are visible, the user is teleported on top of the prim containing the script as a victory honoring.

There is always room for improvement, so feel free to comment (for example, the 3 different particle systems are a bit clumsy).
Here is the script:
Thank you very much again!
{L_CODE}:
//https://community.secondlife.com/forums/topic/444235-quiz-using-dialog-menu/
integer gListen;
integer time;
integer seconds;
key user;
list lChildprims = [2,3,4,5,6,7,8,9,10,1];
integer iChildprim;
integer total;
integer countChildprims;
integer count;
integer gameover;
integer CHANNEL = -808;
integer index;
string answer;

list lSounds = [ "6e517cde-066f-455e-8c6b-f1c33be90dea", "611c9470-507e-4471-8ce2-5ed0962e4c85", "b1e78aa1-52b7-482f-a48a-57e3ddff81fc", "7b978d05-b3bd-4e6f-892f-92dc4845ddd8", "64319812-dab1-4e89-b1ca-5fc937b8d94a", "720ff3dd-8fc6-4523-9670-139df57527f3"];

list quiz = [
// question                     answer  picks (buttons) the pipe | is the delimiter
   "\n \nWho lives in Buckingham Palace?\n \n \n", "Queen", "Queen|Ministers|Lords",
   "\n \nThe White House:\n \nHere lives the President of ...?\n \n \n", "USA", "Britain|Australia|USA",
   "\n \nWhich country is the biggest?\n \n \n", "Canada", "USA|Canada|Britain",
   "\n \nWhere can you find the 'Statue of Liberty'?\n \n \n", "New York City", "Los Angeles|New York City|Washington",
   "\n \nWhich is the capital of the United States?\n \n \n", "Washington", "New York City|Los Angeles|Washington",
   "\n \nWhat was found in California in 1849?\n \n \n", "gold", "oil|gold|natural gas",
   "\n \nWhat did Levi Strauss invent?\n \n
   The first ...", "blue jeans", "car|computer|blue jeans",
   "\n \nWhich material are blue jeans made of?\n \n \n", "cotton", "wool|silk|cotton",
   "\n \nWhat is the name of the 'Freiheits-Statue' in English?\n \n
   The 'Statue of ...'\n \n", "Liberty", "Life|Light|Liberty",
   "\n \nWhat is the capital of Great Britain?\n \n \n", "London", "Washington|London|Sidney"
];

integer stride = 3;
integer quiz_length;
integer question_number;
string correct_answer; // so it's available in the listen event when the user has made their choice
confetti()
        {
            llParticleSystem([PSYS_PART_FLAGS,
            PSYS_PART_EMISSIVE_MASK,
            PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE ,
            PSYS_PART_START_ALPHA,0.5,
            PSYS_PART_END_ALPHA,0.1,
            PSYS_PART_START_COLOR,<1,1,1> ,
            PSYS_PART_END_COLOR,<1,1,1> ,
            PSYS_PART_START_SCALE,<1,1,0>,
            PSYS_PART_END_SCALE,<1,1,0>,
            PSYS_PART_MAX_AGE,4.0,
            PSYS_SRC_MAX_AGE,1.0,
            PSYS_SRC_ACCEL,<0.10,-0.5,-5>,
            PSYS_SRC_BURST_PART_COUNT,1000,
            PSYS_SRC_BURST_RADIUS,1,
            PSYS_SRC_BURST_RATE,5.0,
            PSYS_SRC_BURST_SPEED_MIN,5,
            PSYS_SRC_BURST_SPEED_MAX,15,
            PSYS_SRC_ANGLE_BEGIN,PI,
            PSYS_SRC_ANGLE_END,PI,
            PSYS_SRC_OMEGA,<0,0,0>,
            PSYS_SRC_TEXTURE, llGetInventoryName(INVENTORY_TEXTURE, 0),
            PSYS_SRC_TARGET_KEY, NULL_KEY
            ]);
        }
       
        confetti1()
        {
            llParticleSystem([PSYS_PART_FLAGS,
            PSYS_PART_EMISSIVE_MASK,
            PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE ,
            PSYS_PART_START_ALPHA,0.5,
            PSYS_PART_END_ALPHA,0.1,
            PSYS_PART_START_COLOR,<1,1,1> ,
            PSYS_PART_END_COLOR,<1,1,1> ,
            PSYS_PART_START_SCALE,<1,1,0>,
            PSYS_PART_END_SCALE,<1,1,0>,
            PSYS_PART_MAX_AGE,4.0,
            PSYS_SRC_MAX_AGE,1.0,
            PSYS_SRC_ACCEL,<0.10,-0.5,-5>,
            PSYS_SRC_BURST_PART_COUNT,1000,
            PSYS_SRC_BURST_RADIUS,1,
            PSYS_SRC_BURST_RATE,5.0,
            PSYS_SRC_BURST_SPEED_MIN,5,
            PSYS_SRC_BURST_SPEED_MAX,15,
            PSYS_SRC_ANGLE_BEGIN,PI,
            PSYS_SRC_ANGLE_END,PI,
            PSYS_SRC_OMEGA,<0,0,0>,
            PSYS_SRC_TEXTURE, llGetInventoryName(INVENTORY_TEXTURE, 1),
            PSYS_SRC_TARGET_KEY, NULL_KEY
            ]);
        }
   
    confetti2()
        {
            llParticleSystem([PSYS_PART_FLAGS,
            PSYS_PART_EMISSIVE_MASK,
            PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE ,
            PSYS_PART_START_ALPHA,0.5,
            PSYS_PART_END_ALPHA,0.1,
            PSYS_PART_START_COLOR,<1,1,1> ,
            PSYS_PART_END_COLOR,<1,1,1> ,
            PSYS_PART_START_SCALE,<1,1,0>,
            PSYS_PART_END_SCALE,<1,1,0>,
            PSYS_PART_MAX_AGE,4.0,
            PSYS_SRC_MAX_AGE,1.0,
            PSYS_SRC_ACCEL,<0.10,-0.5,-5>,
            PSYS_SRC_BURST_PART_COUNT,1000,
            PSYS_SRC_BURST_RADIUS,1,
            PSYS_SRC_BURST_RATE,5.0,
            PSYS_SRC_BURST_SPEED_MIN,5,
            PSYS_SRC_BURST_SPEED_MAX,15,
            PSYS_SRC_ANGLE_BEGIN,PI,
            PSYS_SRC_ANGLE_END,PI,
            PSYS_SRC_OMEGA,<0,0,0>,
            PSYS_SRC_TEXTURE, llGetInventoryName(INVENTORY_TEXTURE, 2),
            PSYS_SRC_TARGET_KEY, NULL_KEY
            ]);
        }   
default
{
    state_entry ()
    {
        quiz = llListRandomize (quiz, stride);
        quiz_length = llGetListLength (quiz);
        llSetClickAction(CLICK_ACTION_TOUCH);
        llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>,0.0,PRIM_PHANTOM,TRUE]);
        llSetLinkPrimitiveParamsFast(11, [PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 1.0]);
        //count = llGetListLength(quiz) / 3;
    }

    touch_start (integer num)
    {               
        gListen=llListen(CHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users)
        user = llDetectedKey(0);
        llRegionSayTo(user,0,"Hello, "+ (string)llDetectedName(0) + "!");
        llSetClickAction(8);
        if (llDetectedKey(0) == user) // ignore touches from people not the player
        {
        //index = (index + 1 + (integer)llFrand(count)) % count * 3;
        //}
            llSetTimerEvent(1.0);
            string question = llList2String (quiz, question_number * stride);
            correct_answer = llList2String (quiz, question_number * stride + 1);
            list choices = llParseString2List (llList2String (quiz, question_number * stride + 2), ["|"], []);
            llDialog (llDetectedKey (0), question, choices, CHANNEL);
            ++question_number;
        }
    }
        timer()
   {
    ++seconds;
    time=60-seconds;
    llSetText("time left (seconds): "+(string)time, <1.0, 1.0, 1.0>, 1.0);
    if(time == 0)
    {
        llSay(0, "\n \nYour time is up!\n \n \n");
        llResetScript();
    }
    }   
        listen(integer channel, string name, key id, string message)
{
   if (message == correct_answer)
   {
    llPlaySound("ed124764-705d-d497-167a-182cd9fa2e6c ",1.0);
    llSay(0, "\nThat's correct, " + name + "!" + "\n \n \n");
    total = llGetListLength(lChildprims);
    integer iChildprim=llList2Integer(lChildprims,countChildprims++);
    llSetLinkPrimitiveParamsFast(iChildprim, [PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 1.0,PRIM_PHANTOM,TRUE]);
    //if (question_number * stride == quiz_length)
    if (countChildprims == total)
        {
            llListenRemove(gListen);
            countChildprims = 0;
            llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_PHANTOM,FALSE]);
            llSetText(name + " has won the quiz!", <1.0, 1.0, 1.0>, 1.0);
            llDialog( id, "\n \nGlückwunsch!  Du hast gewonnen!", ["OK"], CHANNEL);
            //llDialog (id, "\n\nThat's all, folks!", ["OK"], CHANNEL);
            //llRezAtRoot(llGetInventoryName(INVENTORY_OBJECT, 0), llGetPos() + <-8.0,5.0,-2.0>,ZERO_VECTOR,llEuler2Rot(<90,0,0> * DEG_TO_RAD)*llGetRot(),0);
            llGiveInventory(id,llGetInventoryName(INVENTORY_OBJECT,0));
            llPlaySound("ed124764-705d-d497-167a-182cd9fa2e6c ",1.0);
            llSay(0, "\n \nDies ist deine Medaille. \n \n Klicke auf 'Behalten', um sie zu behalten.\n \n \n");
            //llSay(0, "\n \nDu hast das Quiz gewonnen, " +name+ ".\n \n \nBerühre die Statue.");
            vector det_pos = llGetPos();
            llSleep(5.0);
            llTeleportAgent(user,"", det_pos+<0.0,0.0,1.5>, <0.0,1.0,0.0>);             
            llSleep(3.0);
            llPlaySound("cheer-hooter-01",1.0);
            llSleep(2.0);
            confetti();
            llSleep(3.0);
            llPlaySound("cheer-hooter-01",1.0);
            llSleep(2.0);
            confetti1();
            llSleep(3.0);
            llPlaySound("cheer-hooter-01",1.0);
            llSleep(2.0);
            confetti2();
            llSleep(10.0);
            llParticleSystem([]);
            llResetScript();
        }       
    else
    {   
      string question = llList2String (quiz, question_number * stride);
      correct_answer = llList2String (quiz, question_number * stride + 1);
      list choices = llParseString2List (llList2String (quiz, question_number * stride + 2), ["|"], []);
      llDialog (id, question, choices, CHANNEL);
      ++question_number;
    }
    }
    else
    {
    llSetText("time left (seconds): 60", <1.0, 1.0, 1.0>, 1.0);
    llSay(0, "\n \nThat's wrong. \n \nYou lose, "+name+".\n \nStart the quiz again.\n \n \n");
    integer iWhichOne = (integer) llFrand( llGetListLength( lSounds ) );
    llPlaySound( llList2String(lSounds, iWhichOne), 1.0);
    llResetScript();
    }
    }
    }


Top
 Profile  
 
 Post subject: Re: randomize questions in quiz without repeating same question
PostPosted: Mon Dec 16, 2019 9:26 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 291
Location: Belgium / Brussels
It's good, it's starting to work but there is still work, it bug a little ... :P

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 5 posts ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net