32 Replies Latest reply on Dec 9, 2008 6:55 AM by fungus13

    Capturing responses to questions

    fungus13 Level 1
      I am creating a quiz, It captures responses to questions and scores them - well it should, but it isn't
      I have array storing random numbers, questions and answers
      Now I want to display the questions and get the responses, these will be scored
      E.g no_correct/total.
      What I'm finding is the response array fills with one to two responses and jumps code
      Can anyone assist?
      questionTest is an array which stored the original answers before they were randomised.
      questionList is a multidimensional array, storing the random questions and associated answers.
      Can anyone put me right?
      At the moment I only get one, at most two questions display before the responseTest array fills (equals no of Questions)
        • 1. Re: Capturing responses to questions
          kglad Adobe Community Professional & MVP
          you have 3 arrays? one storing a master list of questions, one storing a master list of answers and one storing the indices of the questions posed to the user?
          • 2. Re: Capturing responses to questions
            fungus13 Level 1
            I did have two array holding the questions and the answers. Then I applied a randomisation and stored the resultant randomised questions and associated answers in a new array. I would have stored more, but after two variables it was hard to access the contents of the array [Ned's suggestion didn't work]
            questionTest = original questions
            questionList = new ordered questions with answers
            • 3. Re: Capturing responses to questions
              kglad Adobe Community Professional & MVP
              that's a mess. do it the way i suggested.
              • 4. Re: Capturing responses to questions
                fungus13 Level 1
                You put up a solution?
                • 5. Re: Capturing responses to questions
                  kglad Adobe Community Professional & MVP
                  yes, use 3 arrays: one storing a master list of questions, one storing a master list of answers and one storing the indices of the questions posed to the user.
                  • 6. Re: Capturing responses to questions
                    fungus13 Level 1
                    If I interpret what you are saying correctly. I store the random numbers I generated in a third array, which would be in a different order to the questions and answers? How would that help?
                    • 7. Re: Capturing responses to questions
                      fungus13 Level 1
                      If I interpret what you are saying correctly. I store the random numbers I generated in a third array, which would be in a different order to the questions and answers? How would that help?
                      • 8. Re: Capturing responses to questions
                        fungus13 Level 1
                        The code as it stands fills the responseTest array with one response to one question. Changing the contents of the array won't alter the code or the problem. I've tried other rearrangements, without success. One version where I generated random numbers individually almost worked. Went through the first cycle of questions then failed. The code is too long to place here.
                        This is a new attempt where I generated all the random numbers up front. But I'm having a problem controlling the process of Question, answer, store answer, new question. I get question, answer stores six or seven times.
                        • 9. Re: Capturing responses to questions
                          fungus13 Level 1
                          That is why I introduced the tally which ensured one answer per loop, but it still loops without asking another question.
                          • 10. Re: Capturing responses to questions
                            Ned Murphy Adobe Community Professional & MVP
                            I think fungi's problem lies in not knowing how to deal with the three arrays that were recommended. My suggestion had nothing to do with the code shown up top. And I am at a loss to try to figure out from that code what's being attempted.
                            • 11. Re: Capturing responses to questions
                              fungus13 Level 1
                              Hi Ned
                              Basically I have the three arrays (or two if you use the combined array)
                              I've had a rather bad attempt at asking the user a question, storing the answer in an array (another one called responseTest) and asking a new question.
                              The final array (responses was to be compared to the answers and scored)
                              I failed badly.
                              • 12. Re: Capturing responses to questions
                                Ned Murphy Adobe Community Professional & MVP
                                What does the user interact with when they submit an answer?
                                • 13. Re: Capturing responses to questions
                                  fungus13 Level 1
                                  I had no problem with the practice exercise, where the user could press any key. Then press another button to get the next question. Worked without a hitch. But trapping one question and moving on on one button press 'Test' has caused me some grief.
                                  • 14. Re: Capturing responses to questions
                                    fungus13 Level 1
                                    I had no problem with the practice exercise, where the user could press any key. Then press another button to get the next question. Worked without a hitch. But trapping one question and moving on on one button press 'Test' has caused me some grief.
                                    • 16. Re: Capturing responses to questions
                                      fungus13 Level 1
                                      They don't, the screen displays the next answer. Well it was mean't to. But with my code the next question never comes up, because the responseTest fills with one response (a keypress) which I capture from the stage.
                                      • 17. Re: Capturing responses to questions
                                        Ned Murphy Adobe Community Professional & MVP
                                        What is the nature of the answers? Are they single keypress values (such as 0 thru 9)?
                                        • 18. Re: Capturing responses to questions
                                          fungus13 Level 1
                                          It is a piano keyboard. The values (13 possible keys) are set with a switch statement e.g.
                                          switch (event.keyCode) {
                                          case 81 :
                                          mcC_one.play();
                                          break;

                                          I capture the keyPress via

                                          function reportKeyDown3(event:KeyboardEvent):void {
                                          trace("Key Pressed: " + String.fromCharCode(event.charCode) +
                                          " (Key code: " + event.keyCode + ")");

                                          etc

                                          All that works

                                          I looked at the code put up. I get caught at the SubmitBtn
                                          don't know how to handle that. There is only one button press - to start. That was also to start the clock, but that is another story.


                                          • 19. Re: Capturing responses to questions
                                            Ned Murphy Adobe Community Professional & MVP
                                            kGlad's submitBtn will become (be replaced by) your keypress event being captured. But if answers can have a different number of keypresses, then things would get complicated in terms of determining when someone has finished answering a question.
                                            • 20. Re: Capturing responses to questions
                                              fungus13 Level 1
                                              That is the core of the problem
                                              Capturing the response
                                              Hence the code, which failed of course
                                              I want to look at the stage, capture the answer, store it and move on to the next question. I can do it with two buttons, and almost with one. But as I said that code is too long to place here.
                                              • 21. Re: Capturing responses to questions
                                                fungus13 Level 1
                                                Is it possible to get a question/answer routine without involving the keypress capture? The code is inside the keycapture function. Which works fine.
                                                • 22. Re: Capturing responses to questions
                                                  Ned Murphy Adobe Community Professional & MVP
                                                  If the users will have mouses, then kGlads code would work as is (I'm not sure if it advances from one question to the next though... I may have missed seeing that). All's you would need is to add a btn and give it an instance name submitBtn.

                                                  An alternative could be to use another keypress as the indicator that an answer is ready for submittal. In this case, you don't need to monitor the keypresses for the answers at all, just whichever key that is used to ignite the answer capturing function (like the ENTER key)... though you might want to capture the keyUp event rather than the keyDown..
                                                  • 23. Re: Capturing responses to questions
                                                    WebXperience Level 1
                                                    You're probably finished with this project, but I came across a great book which contains a more streamlined version of a "Trivia Quiz." Its name: ActionScript 3.0 Game Programming University . At the book's website you can download the code for the quiz. Hope this helps.
                                                    • 24. Re: Capturing responses to questions
                                                      fungus13 Level 1
                                                      Hi all, I've been in town. Intended to pick up a computer, but didn't happen, Oh well such is life.
                                                      I have almost solved this problem for a single generated random number so there must be a solution. I can't believe there isn't. The keypresses are taken care of. The user plays the key (piano) to answer the question, Forget that bit. The input is what I call it. E.g. when the user hits the letter "q" it is recognised as the note "Middle C" That bit works. The program recognises this input as "C", "D", "E" etc as soon as the associated key is pressed.
                                                      What I need, is to refigure my code to display a question, wait for the answer ("C" etc) and when it is given capture (push) it on an array (responseTest) and display the next question (questionTest). I need a method of holding the code until the response is recognised then when it is given, proceed to the next question (display on screen e.g. as tbQ.text) until the number of responses equal the number of questions. I have already successfully scored the results once the response Array (responseTest in this case) is filled. My problem is filling this response array in an effective manner.
                                                      I've tried a number of code configurations. The one posted is probably not my best, but waS short and I had hoped sufficient to get message across. But I seem to have failed there too.
                                                      I can randomise separately and generate the initial array, so that doesn't necessarily have to be part of the code, but could be. I found I had more control when it was, but I was attempting to solve the problem but running subroutines - a routine for each step. Perhaps that was the wrong way to tackle it. Does that help?
                                                      • 25. Re: Capturing responses to questions
                                                        Ned Murphy Adobe Community Professional & MVP
                                                        You probably need to take this off the machine for awhile and outline it all logically on paper first--first write it out in plain english, detail step by detail step. Then create code that follows those steps.

                                                        You can probably use the keyboard events to do what you want, but if the number of keypresses for answers varies from one answer to the next, you're in for some complicated coding if you want to make this quiz user friendly. The more efficient way to approach this has been offered.

                                                        And it helps on the logical planning side of things, and on the readability side of things, when you do separate your code into different functional sections/routines... especially a year or more from now when you need to change something and have to figure out what you did.
                                                        • 26. Re: Capturing responses to questions
                                                          fungus13 Level 1
                                                          I did try writing out the steps, as you said, but obviously missed something. The response array filled without the second question being asked, it just repeated my keypress. Haven't yet figured why. When I tried to trap it with additional if's it stopped in it's tracks and wouldn't save to the response array. Somewhere in between is the answer
                                                          The keypress is one per question at the moment, My plan would be to have equal numbers of keypresses for each question in a group. Eg. I would set up a set of similar questions with just the notes varying not the number of notes.
                                                          I have the feeling that the single keypress is interpreted so fast that one press is being interpreted as seven. Somehow I have to define that keypress as one answer only e.g. press and release = one response. I think the time I hold it down is sufficient to cause the array to fill. If that is true, I don't know how to code that trap. Might need some sort of "holding" statement that I haven't yet come across yet.


                                                          • 27. Re: Capturing responses to questions
                                                            fungus13 Level 1
                                                            Of course I could be wrong, but that is what I suspect
                                                            • 28. Re: Capturing responses to questions
                                                              Ned Murphy Adobe Community Professional & MVP
                                                              As I mentioned earlier, if you look for the keyUp event rather than the keydown event, you are less likely to run into a case of multiple keypresses.... only one up happens for a key event, but down can fire continuously as long as the key is down.
                                                              • 29. Re: Capturing responses to questions
                                                                fungus13 Level 1
                                                                I see your point
                                                                • 30. Re: Capturing responses to questions
                                                                  fungus13 Level 1
                                                                  However, how would that affect the "playing" of the keys. I'd need to run both if I want the piano to behave realistically, that is sound on the "down" but trap on the up.
                                                                  • 31. Re: Capturing responses to questions
                                                                    fungus13 Level 1
                                                                    Not quite sure how that would affect the code. I assume I'd have to re-define it between the switch or equivalent and the code that runs the test.
                                                                    • 32. Re: Capturing responses to questions
                                                                      fungus13 Level 1
                                                                      something like this?
                                                                      Although I'm a bit weak on redefining functions

                                                                      function reportKeyDown(event:KeyboardEvent):void {
                                                                      trace("Key Pressed: " + String.fromCharCode(event.charCode) + " (Key code: " + event.keyCode + ")");

                                                                      switch (event.keyCode) {
                                                                      case 81 :
                                                                      mcC_one.play();
                                                                      break;
                                                                      case 50 :
                                                                      mcDft_one.play();
                                                                      break;
                                                                      etc


                                                                      REST OF CODE TO catch responses, score and output would go here



                                                                      function reportKeyUp(event:KeyboardEvent, keycode):String {
                                                                      trace("Key Pressed: " + String.fromCharCode(event.charCode) + " (Key code: " + event.keyCode + ")");

                                                                      if (event.keyCode == 89) {
                                                                      keyNote = "A";
                                                                      //mcA_one.play();
                                                                      }
                                                                      if (event.keyCode == 85) {
                                                                      keyNote = "B";
                                                                      //mcB_one.play();
                                                                      }

                                                                      return keyCode;
                                                                      }
                                                                      stage.addEventListener(KeyboardEvent.KEY_UP,reportKeyUp);


                                                                      }
                                                                      stage.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);