Announcement

Collapse
No announcement yet.

Help with randomizing questions and answers in a quiz application

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with randomizing questions and answers in a quiz application

    OK. So I am working to try to randomize questions and the answers for the questions and then do a TextObject(text1) Set.Text (whatever).

    I have it worked out to randomize the questions, at lease the first one. But when I get to the answers I am having problems. I tried to do use an IF statement to not select an index but it ties up the program. It works for the first two questions but the program hangs on the third question

    Redo3
    %RndAnswer% = VariableSetRandomValue (Number, 1, 4)
    IF (%RndAnswer% = %A1% or %A2%)
    GOTO (Redo3)
    EndIF
    %A3% = %RndAnswer%
    Then I proceed to set a TextObject to the value located at the Random Value if it does not match %A1% or %A2%. But like i said it hangs.

    OK, So then I think, well if it doens't like that, maybe I will try to remove the value once it is populated on the page. The problem I run into is the delimiter. If the random value that is chosen is the first or last, the delimiter is left in place and I occasionally get a blank field.

    Anyone have suggestions on how to get a random value from a string and assign it to a text object and move on to the next.

    I have attached the project to show what I am trying to do.

    13660-test proggie.zip
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  • #2
    Re: Help with randomizing questions and answers in a quiz application

    Tig-
    Only the answers need to be randomize for a specific question, but then the correct answer must be stored in a variable no matter how the answers are randomized. Does that make sense?

    Comment


    • #3
      Re: Help with randomizing questions and answers in a quiz application

      That makes sense on randomizing the answers, but if you can randomize the answers, you should just as easily randomize the questions as well.

      As far as the answers, have them click on an answer to select what they think is the right answer, or if it is a fill in the blank, provide an Edit Field for them to fill in. When they select their answer, store it in a variable, %AnswerToQuestion1% or something along those lines.

      When they answer, do you want them to be able to see if it is correct immediately or at the end of the quiz?

      What format are the questions going to be stored in? A text file?

      Depending when they find out if they are correct in their answer, you could do a couple of things. If it is immediate, you could to an IF/ENDIf statement that compares their answer to an answer on the CD, if it is a match, then Show a Correct image or something along those lines.

      If you want to wait until the end, you could, upon hitting the Next key, have it evaluate a Variable %CorrectAnswers% by one if the answer is correct.

      If (%answerQ1% = %AnswerKeyQ1%)
      %CorrectAnswers% = Evaluate(%CorrectAnswers% + 1)
      ENDIF
      Page.Jump (%PageNext%)

      And when they are finished with the quiz, you can have a button that e-mails their scores, or gives them their final score.
      "On Click"
      %Score% = Evaluate ((%CorrectAnswers% / 10) * 100)
      TextObject (score) Set.Text (Your score is %Score%%)

      Does that help?

      I am stuck on the randomizing of the answers to the question. I am trying to use a string from a text file and randomly grab an index and set a text object, at the same time trying to make sure that I don't duplicate the earlier answers. This is where I am having problems. I am sure there is a simpler way to do it. I will keep tinkering when time permits, but hopefully someone who has done this will speak up and part with their wisdom. If I figure out a way, I will definately post it.

      I will keep thinking about it.

      Tigger
      TJ-Tigger
      "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
      "Draco dormiens nunquam titillandus."
      Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

      Comment


      • #4
        Re: Help with randomizing questions and answers in a quiz application

        Tig-
        The end user will NOT see if they got it right or wrong immediately just a pass or fail at the end of the test.

        "What format are the questions going to be stored in? A text file?"
        Well I would assume a text file would be te way to go. That way anyone could apply this test to their own project.

        Thx for your help on this!

        Bruce

        Comment


        • #5
          Re: Help with randomizing questions and answers in a quiz application

          I have something cool working now. I have to run an errand, I will post a working version a little later.

          It is cool.
          TJ-Tigger
          "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
          "Draco dormiens nunquam titillandus."
          Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

          Comment


          • #6
            Re: Help with randomizing questions and answers in a quiz application

            TJ_Tigger, since random numbers are, well, numbers, why not use a method that will allow you to use them as indexes?

            If you store the questions and answers in a text file or in delimited strings, you can just generate a random number for the index, and then use a Get Line or Get Delimited String action to grab the text at that index. No IFs needed at all.

            Heck, you could even use a global list.
            --[[ Indigo Rose Software Developer ]]

            Comment


            • #7
              Re: Help with randomizing questions and answers in a quiz application

              That is what I was doing. The problem I was running into and wanted to avoid, was to have an answer populate twice for the same question. So I needed to find a way to remove the index(s) or ensure that the already chosen indexes were not rechosen again.

              I have it working, just doing some fine tuning right now. Will have it posted soon.

              Tigger
              TJ-Tigger
              "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
              "Draco dormiens nunquam titillandus."
              Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

              Comment


              • #8
                Re: Help with randomizing questions and answers in a quiz application

                If you're using a delimited string, then replace the item at that index with "", and then replace any double delimiters with a single delimiter. Subtract 1 from the questions-remaining counter. If you have duplicate items in the list, then use another list as a "lookup table"...this one stores the indexes of items (in the "real" list) that have yet to be picked. You pick one of them at random, then use that index to grab the appropriate question or answer from the "real" list.

                If you're using a global list, just remove the item from the list.
                --[[ Indigo Rose Software Developer ]]

                Comment


                • #9
                  Re: Help with randomizing questions and answers in a quiz application

                  How would you know what the correct answer was for each question?

                  Comment


                  • #10
                    Re: Help with randomizing questions and answers in a quiz application

                    Depends on whether you have the questions/answers together in the same list (e.g. q::a) or in separate lists. If in separate lists, just perform the same removal in both.

                    If you're using the lookup table method, then you just leave the answers list alone, and grab the item from the answers list using the index from the lookup table list.

                    Like this: Random number? Uh, 5. Okay, get fifth item in lookup table list. What is it? Ah, the number "7". Okay, we grab item 7 from the Questions list, and item 7 from the Answers list.

                    'Course, that's just one method. There are as many different ways of doing this as you can think up.
                    --[[ Indigo Rose Software Developer ]]

                    Comment


                    • #11
                      Re: Help with randomizing questions and answers in a quiz application

                      Here try this. Not at quality yet, but it works up to a point.


                      13706-test proggie.zip
                      TJ-Tigger
                      "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                      "Draco dormiens nunquam titillandus."
                      Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                      Comment


                      • #12
                        Re: Help with randomizing questions and answers in a quiz application

                        I was using a string to do this and I did the removal of the item and replaced with "" but it didn't work for the first and last items. So I changed to a IF/ENDIF statement where I look to see if it is the item located at the Last index and if it is I removed the ::%variable% to make sure that I removed the delimiters along with the indexed item. Works nice. If it is not the last item I would I would remove %Variable%::. This would take care of the first one in the list and all others to make sure that I didn't have double delimiters or a flase item at the front of the list or the end of the list.

                        As far as finding the correct answer, I have the example above set up to send the questions and answers to the person specified in the mailto address. I was going to work on another file that would contain the correct answers and do a compare when the person clicks next.

                        The other thing I was thinking about adding was a Back button but would need to incorporate a IF/ENDIF statement so that I don't respawn the questions.

                        I will still play with it.
                        TJ-Tigger
                        "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                        "Draco dormiens nunquam titillandus."
                        Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                        Comment


                        • #13
                          Re: Help with randomizing questions and answers in a quiz application

                          Your an ANIMAL!

                          Comment


                          • #14
                            Re: Help with randomizing questions and answers in a quiz application

                            Here try this one. When you hit next, it checks the answer selected against an answer sheet (answers.txt). Obviously you would want to rename this file so it does not say answers or show as a .txt file.

                            The final page shows your total score and if you guess correct it tells you that you got it correct.

                            Enjoy

                            13723-test proggie.zip
                            TJ-Tigger
                            "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                            "Draco dormiens nunquam titillandus."
                            Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                            Comment


                            • #15
                              Re: Help with randomizing questions and answers in a quiz application

                              TJ_Tigger, it's easier/faster to just replace the variable (without the delimiter) with an empty string, and then immediately perform another replace to replace any double delimiters with single ones.

                              Example:

                              Replace %variable% with ""
                              Replace :::: with ::

                              That will automatically take care of all cases (i.e. single item, not-last item with delimiter, last item with no delimiter).
                              --[[ Indigo Rose Software Developer ]]

                              Comment

                              Working...
                              X