20 Replies Latest reply on Feb 7, 2017 1:46 AM by AMULI

    Making a quiz

    jackh8500410 Level 1

      Hi All,

       

      I have a fully functioning quiz game which contains 10 questions. The user is asked a question and they click an answer.

      The system I have to prevent duplicate questions being asked is to set a variable "TotalQu" equal to 10

       

      For some reason, only 9 questions are being asked - TotalQu = 10. If I increase TotalQu to 11, all 10 questions are asked but then it loops because its looking for another question.

       

      Thanks,
      Jack

        • 1. Re: Making a quiz
          ClayUUID Adobe Community Professional

          So... did you have a question?

          • 2. Re: Making a quiz
            jackh8500410 Level 1

            Any troubleshooting tips on how to stop it from doing this...

            I want it to ask 10 out of 10 questions.

             

            I didn't want to clog up the post with loads of code.

            • 3. Re: Making a quiz
              ClayUUID Adobe Community Professional

              Okay, so you understand there's a nearly infinite number of ways to code a quiz. Without looking at your code, the absolute best anyone here can do is randomly guess what your problem might be.

               

              At the moment the only thing I know about your code is that this exists somewhere within it:

               

              // prevent duplicate questions being asked

              var TotalQu = 10;

              • 4. Re: Making a quiz
                jackh8500410 Level 1

                I'm very aware of that, thanks.

                 

                This is set on the first frame;

                //variable to not ask any more questions than 10.

                var TotalQu:Number = 10;

                 

                On all of the other frames is;

                //only show if SeltUsedQu = 0 (question not shown before)

                if(SeltUsedQu1 == 0){

                 

                  TotalQu--;

                  trace(TotalQu);

                  if (TotalQu == 0)

                  {

                  gotoAndStop("TestOver");

                  }

                } else {

                gotoAndPlay("DupQu");
                //generate different question

                }

                 

                I think I may have figured out the problem;

                When TotalQu is set to 10, it will get to the last question but TotalQu will equal 0, so the code is sending it to TestOver. Should I increase my IF statement by 1 and set TotalQu to 11?

                 

                Thanks.

                • 5. Re: Making a quiz
                  AMULI Level 4

                  You could simply move your decrement statement (TotalQu--;) into the else block.

                  • 6. Re: Making a quiz
                    jackh8500410 Level 1

                    I want it to be decremented when the frame is played, not when it goes to the Duplicate Question frame.

                    • 7. Re: Making a quiz
                      AMULI Level 4

                      Sorry. Without knowing your score logic, it's difficult to answer

                      • 8. Re: Making a quiz
                        jackh8500410 Level 1

                        That's alright, I know how difficult it is to give help over the internet!

                        So at the start of the quiz I have 10 of these:

                         

                        //Prevent same question being asked twice

                        var SeltUsedQu1:Number = 0;

                         

                        When the question has been asked, the 0 will be replaced with a 1 so it cannot be played again.

                         

                        TotalQu starts at being 10 and is then decremented by 1 on each question with the code in my previous post.

                         

                        Hope this make more sense?

                         

                        Thanks

                        • 9. Re: Making a quiz
                          ClayUUID Adobe Community Professional

                          Wait, are you really doing...

                           

                          var SeltUsedQu1:Number = 0;

                          var SeltUsedQu2:Number = 0;

                          var SeltUsedQu3:Number = 0;

                          var SeltUsedQu4:Number = 0;

                          var SeltUsedQu5:Number = 0;

                          var SeltUsedQu6:Number = 0;

                          var SeltUsedQu7:Number = 0;

                          var SeltUsedQu8:Number = 0;

                          var SeltUsedQu9:Number = 0;

                          var SeltUsedQu10:Number = 0;

                           

                          Instead of just...

                           

                          var SetItUsedQ:Array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

                           

                          ?

                           

                          Why is the logic to check if a question has already been asked inside the question frame itself? Shouldn't that be consolidated in the code that selects the next question?

                          1 person found this helpful
                          • 10. Re: Making a quiz
                            jackh8500410 Level 1

                            I used a tutorial for this game and adapted it to my needs, its the best I could do.

                            The SeltUsedQu at the top of every frame is what I thought was the way to either send the user to another question or play the frame if it had not been asked.

                             

                            Yes, I have got 10 variables on my first frame.

                            • 11. Re: Making a quiz
                              AMULI Level 4

                              Please give enough information to allow actual help :

                              • Where is the questions/answer data : in hard in the score, in code, in external file ?

                              • What is the score logic ?

                               

                              Could you share a source file I could examine, even a simplified version ?

                              • 12. Re: Making a quiz
                                jackh8500410 Level 1

                                The questions and answers are just a text box which have been converted into a symbol, picture below;

                                Capture.PNG

                                I'm unsure as to what you mean by score logic? I'm assuming like a points system, so 1 point for a correct answer?

                                If I'm correct then-

                                var Points = 0; //set on the start of the quiz

                                when the user clicks the correct answer, a point is added;

                                //Question: Correct

                                QuBk1True_Btn.addEventListener(MouseEvent.CLICK, QuBk1True);

                                function QuBk1True(event:MouseEvent):void

                                {

                                  Points = Points + 1;

                                  SeltUsedQu1 = 1;

                                  gotoAndStop(5);

                                }

                                Capture2.PNG

                                • 13. Re: Making a quiz
                                  ClayUUID Adobe Community Professional

                                  Okay, imagine what would happen in your code if you had one question, so you set TotalQu to 1.

                                   

                                  The very first thing it does is decrement TotalQu. Before it's even asked the question. Which would cause it to immediately jump to TestOver.

                                   

                                  Changing the TotalQu == 0 comparison to < 0 might fix it, but then you still haven't revealed the code that "generates" the next question, which apparently also checks this variable.

                                  • 14. Re: Making a quiz
                                    AMULI Level 4

                                    Yes, in a quizz context "score logic" would be evidently understood as the logic for counting points (I should have thought to that… but I'm French ). I meant the logic in your score window : the frames and how you jump from one to the other. For example, if you have a different frame for each of the ten questions, I do'nt understand the need for those ten Boolean variables ?

                                     

                                    Like ClayUUID, I'd like to understand what does it exactly means to "generate" the next question ? This suggests that the questions aren't hard-coded in your score ?

                                    Enregistrer

                                    • 15. Re: Making a quiz
                                      jackh8500410 Level 1

                                      Please don't take anything I say badly... I'm just as bad with coding

                                      So when it generates a new question it is playing frame 5, the code for that is;

                                       

                                      var SelRam:Number = Math.random();

                                      SelectQu = Math.round(SelRam*9+1);

                                       

                                      stage.addEventListener(Event.ENTER_FRAME,EntFrame);

                                      function EntFrame(e:Event):void

                                      {

                                        if (SelectQu == 1){

                                        gotoAndStop("QuBk1");

                                        SelectQu = 0;

                                        }

                                       

                                        if (SelectQu == 2){

                                        gotoAndStop("QuBk2");

                                        SelectQu = 0;

                                        }

                                       

                                      and so on... up to 10.

                                       

                                      I have 10 frames, 1 frame for each question. I know it's not the best, but I found it helpful with the tutorial.

                                      • 16. Re: Making a quiz
                                        AMULI Level 4

                                        Please don't take anything I say badly... I'm just as bad with coding

                                        You're welcome, Jack You were just not providing enough information for us to help ! It's now getting clearer

                                         

                                        I know understand why you needed those Boolean values to check already answered questions : you display the ten questions in a random order (important missing piece of the puzzle ).

                                         

                                        The problem with your frame 5 code is that the random value between 1 and 10 could be the number of an already answered question (hence the need for a Boolean).

                                         

                                        I suggest that in frame 1 you build a random permutation of the natural sequence 1, 2, 3, 4, 5 (I suppose only 5 questions) : take a random value in that array and move it into the second array (initially empty) ; repeat with the four remaining values ; three, two, one, repeat until the array is empty.

                                         

                                        var defaultOrder: Array = [1,2,3,4,5];

                                        var randomOrder: Array = [];

                                        var randomIndex, nextQ: Number;

                                        while (defaultOrder.length > 1)

                                        {

                                            // random index in the remaining items of defaultOrder array

                                            randomIndex = Math.random() * defaultOrder.length;

                                         

                                            // get the value at that random index and remove it from the defaultOrder array

                                            nextQ = defaultOrder.splice( randomIndex, 1);

                                         

                                            // add the value to the randomOrder array

                                            randomOrder.push( nextQ);

                                        }

                                        // one value remaining in defaultOrder array

                                        nextQ = defaultOrder.pop();

                                        randomOrder.push( nextQ);

                                         

                                        // the randomOrder array now contains a random permutation of the original defaultOrder array

                                        trace( randomOrder);

                                         

                                        Now nextQ = randomOrder.pop() will give you the next question to display.

                                        And you just go to the corresponding frame via gotoAndStop("QuBk" +nextQ); (building the frame label by string concatenation).

                                         

                                        If it helps, I may post a FLA file with that kind of structure (visiting frames in random order) you could build upon.

                                         

                                         

                                         

                                         

                                         

                                         

                                         

                                         

                                        Enregistrer

                                        1 person found this helpful
                                        • 17. Re: Making a quiz
                                          AMULI Level 4

                                          Here is a view of the timeline window (I called it before "score window", which is the name in Director ! May be it's called "timeline window" in the US version of Animate ?) :

                                           

                                          Capture d’écran 2017-02-05 à 20.43.19.png

                                           

                                          All code in frame 1 (at other frames, only this.stop();) :

                                           

                                          this.stop();

                                          //------------------------------------

                                          // Compute a random permutation of the natural sequence

                                          //------------------------------------

                                          var defaultOrder: Array = [1,2,3,4,5];

                                          var randomOrder: Array = [];

                                          var randomIndex, nextQ: Number;

                                          while (defaultOrder.length > 1)

                                          {

                                              // random index in the remaining items of defaultOrder array

                                              randomIndex = Math.random() * defaultOrder.length;

                                           

                                              // get the value at that random index and remove it from the defaultOrder array

                                              nextQ = defaultOrder.splice( randomIndex, 1);

                                           

                                              // add the value to the randomOrder array

                                              randomOrder.push( nextQ);

                                          }

                                          // one value remaining in defaultOrder array

                                          nextQ = defaultOrder.pop();

                                          randomOrder.push( nextQ);

                                          //------------------------------------

                                          // Handling the jump to the next question

                                          //------------------------------------

                                          nextQuestion.addEventListener( MouseEvent.CLICK, goToNext);

                                          function goToNext( evt: MouseEvent)

                                          {

                                              if (randomOrder.length > 0)

                                              {

                                                  nextQ = randomOrder.shift();

                                                  this.gotoAndStop( "question" +nextQ);

                                              }

                                              else

                                              {

                                                  this.gotoAndStop( "results");       

                                              }

                                          }

                                          //------------------------------------

                                           

                                          The FLA source file is downloadable here : https://app.box.com/s/yebmfjp8n0ecedxra9cujd788x9ettzx

                                          Enregistrer

                                          1 person found this helpful
                                          • 18. Re: Making a quiz
                                            jackh8500410 Level 1

                                            Thanks AMULI, you're a star!

                                            I'll have a look through and adapt to mine, it's making sense that's for sure!

                                             

                                            Will let you know how I get on

                                            • 19. Re: Making a quiz
                                              jackh8500410 Level 1

                                              AMULI, managed to get it all working, thanks again for your help

                                              I'm sure I'll be back again for more help!

                                               

                                              Thanks again,

                                              Jack

                                              • 20. Re: Making a quiz
                                                AMULI Level 4

                                                Glad to learn you succeeded and happy to help jackh8500410