3 Replies Latest reply on Nov 27, 2006 2:40 AM by Leegee3

    Loading random frames?

    Leegee3 Level 1
      Using Director MX 2004.

      I have created a simple quiz, consisting of 10 questions. Each question is on a separate frame/page.

      Instead of having the same question come up everytime you run the quiz, is it possible to load each question/frame randomly, but not allowing the same question/frame to come up more than once.

      I hope that makes sense to you all.


      Lee
        • 1. Re: Loading random frames?
          Level 7
          Give each of the question frames a name and put this name onto the
          frameLabel of each. For ease of explanation, I'll name them "q1", "q2",
          etc...

          On the "main" frame, make it go to a random frame, and once the question
          is answered, go back to the main frame (which will go to another random
          frame).

          Each time you make a jump to a random question frame, add the name of
          that frame to a list. Each time that you make a new jump, look in the
          list to make sure that the question has not been gone to already.

          If there are no more questions left (or if that list has 10 entries),
          then go to the score frame or whatever you want to do after the quiz is
          over. In my example, we jump to a frame named "done".

          Something like this (untested off the top of my head code here):

          main frame script
          -----------------

          global gFramesDone

          on exitFrame me

          --make the list if it isn't there already
          if voidP(gFramesDone) then gFramesDone=[]

          --make sure that the list isn't complete
          --if it is complete, then go to the done page
          if gFramesDone.count=10 then
          go "done"
          pass
          end if

          --pick a random number between 1 and 10
          jumpTo=random(10)

          --compare it to the list
          repeat while gFramesDone.getOne(jumpTo)>0
          --that number has been done, try another
          jumpTo=random(10)
          next repeat
          end repeat

          --add this one to the list
          gFramesDone.add(jumpTo)

          --jump to the appropriate frame
          go "q"&jumpTo --change this to the actual label of your frames
          end

          behaviour script that is on the button that the user uses to either get
          the next question or accept their answer on the current one:
          -------------

          on mouseUp me
          go "main"
          end
          • 2. Re: Loading random frames?
            Level 7
            It's fairly easy to implement this functionality. You start off with a List
            of frames which have a question. Using the Random() function you randomly
            select one of the list items, remove that item from the list then navigate
            to the selected frame. The list gets smaller after each question. Once the
            list is empty the quiz is over.

            ---Example movie script---

            global gQuestionList

            on prepareMovie
            gQuestionList = [5,10,15,20,25,30]
            end

            on selectRandomQuestion questionList
            if questionList.count = 0 then
            return 0
            else
            selectedQuestion = questionList[random(1,questionlist.count)]
            questionList.deleteOne(selectedQuestion)
            return selectedQuestion
            end if
            end

            --- end of script ---

            How you implement this will depend on your existing code but somewhere you
            propably already have something that moves the user from frame to frame. It
            is there you will call the function to randomly select a frame to navigate,
            like this selectRandomQuestion(gQuestionList)




            • 3. Re: Loading random frames?
              Leegee3 Level 1
              Hey guys, thanks for that, its a great help.