7 Replies Latest reply on Jul 15, 2014 1:17 PM by Sean_Wilson

    Director 11.5- Creating a Random Button

    SSardarGloucester Level 1

      Hiya! I am creating a karaoke product using Director 11.5 and in the main menu, i wanted to add the option of for the user to click on a button named 'Random'. This obviously meant that somehow the product would choose a song for the user....umm...is there anyway to do this?....Anyone? I look forward to hearing from you guys!

        • 1. Re: Director 11.5- Creating a Random Button
          jchunick Level 2

          you can use the random() method

           

          for example:

           

          -- behavior script attached to your 'random' button

          on mouseUp me

            i = 120 -- number of songs

            rnd = random(120)

            sound(1).play(member("karaokeX"))

          end

           

          without more information on how you have things configured there's really no way to help.

          • 2. Re: Director 11.5- Creating a Random Button
            James Newton, ACP Level 3

            You can use random() to choose a random number.  If you have 17 song titles, then you could use:

             

            vRandomSongNumber = random(17)

             

            Suppose your other buttons do something like this:

             

            on mouseUp()

              PlaySong(3) -- or whatever system you use to decide which song to play

            end mouseUp

             

            Your random button could do this:

             

            on mouseUp()

              vRandomSongNumber = random(17) -- or however many songs there are to choose from

              PlaySong(vRandomSongNumber)

            end mouseUp

             

            Does that help?

            • 3. Re: Director 11.5- Creating a Random Button
              SSardarGloucester Level 1

              umm...kinda?...I'm sorry i am a beginner at Director...only an A2 student!We only have to have 3 songs....Right! to get it to go to the next page, i have the markey way, so on Mouse Down, go to Marker 7 for example...umm...how would i do that with the random button thing?....do i enter the name of the song after it?....the sprite number?...i am so confused...

              • 4. Re: Director 11.5- Creating a Random Button
                James Newton, ACP Level 3

                Let's imagine that your song markers are at frames 7, 14 and 35 (I've deliberately chosen frames which are not consecutive).  You could create a list of frame numbers:

                 

                vSongFrames = [7, 14, 35]

                 

                The behavior on your Random button could look like this:

                 

                on mouseUp()

                vSongFrames = [7, 14, 35] -- <HARD-CODED>

                 

                vSongCount = vSongFrames.count

                vRandomSong = random(vSongCount)

                vRandomFrame = vSongFrames[vRandomSong]

                go vRandomFrame

                end mouseUp

                 

                What does this do?  It stores all your data concerning the frames that you could jump to in one place.  If you change the frame numbers, or the number of songs, you make that change in just one place.  In  the next 4 lines, the code:

                • Calculates how many songs you have, using the list of frame numbers as a guide
                • Chooses one of those songs at random
                • Works out which frame that song starts on
                • Jumps to that frame

                 

                It's not normally a good idea to use hard-coded frame numbers.  You might decide to add frames or move the markers in the Score.  If you did that, the behavior would no longer work.  It would be better to use frame labels...

                 

                vSongFrames = ["Name of marker for first song", "Second song", "Third song"]

                 

                ... where the strings you use in the list are identical to the names of the markers in your movie.  You would still be hard-coding data, but that data is less likely to change.  Assuming that the marker label at frame 14 is "Second Song" then the commands...

                 

                go 14

                -- AND

                go "Second Song"

                 

                ... have exactly the same effect.

                • 5. Re: Director 11.5- Creating a Random Button
                  SSardarGloucester Level 1

                  Thank you so much! That was a lot of help! Thanks for doing it step by step as well!

                  • 6. Re: Director 11.5- Creating a Random Button
                    loyloy gatong

                    How about for example the frame start with 10 - 20 and the frame interval is 2 , then how would you randomized the frame  without repeating the number? thanks !!!

                    Please help me!!! i'm just a student and i am working my special project called CAI.... thanks a lot for scrutinizing my message..

                    • 7. Re: Director 11.5- Creating a Random Button
                      Sean_Wilson Adobe Community Professional

                      I'm not sure I understand your question, but supposing your frame numbers were placed in a list it might look like:

                      lFrames = [10, 12, 14, 16, 18, 20]

                      Then you could choose one of those items like James outlined. In order to not repeat the number you would remove it from the list