4 Replies Latest reply on Feb 28, 2007 10:53 AM by Newsgroup_User

    testing for conditions until true

    Opera Rat
      I can't seem to test for a condition more than once. The first time my alert box pops up and if I just hit ok then regardless of whether the condition is met the program goes on.

      I want to test for the number of tracks on a CD. If incorrect number of tracks on CD then alert box if correct then play. Just like when you load software and it checks for CD1 or 2 and keeps asking you to insert the correct CD until you do. You probably won't recognize the Xtras commands, but I'm sure you can figure out what they do.

      on exitFrame

      if dmm_CDExtGetTotalTracks() <> 4 then
      alert "Please insert correct CD"
      else
      playCD
      end if
      end

      Strange things happen. Sometimes it will just play the wrong CD and if I close director it keeps playing and there is no player open and no way to stop it without removing it.


        • 1. Re: testing for conditions until true
          Level 7
          You can set up an endless repeat loop and only exit the loop when the
          correct CD is in the drive. **Warning- untested off the top of my head
          code**

          repeat while true
          if dmm_CDExtGetTotalTracks() <> 4 then
          alert "Please insert correct CD"
          else
          playCD
          exit repeat
          end if
          end repeat

          You have to be very careful, though, since if the correct CD is never
          put in, then the loop will never end, and you'll need to kill the
          program manually by ending the task.

          It is a better idea to use an xtra like BuddyAPI's baMsgBox instead of
          that alert. With baMsgBox, you can have an ok and a cancel button. If
          the user hits cancel, it can exit the loop more gracefully.
          • 2. Re: testing for conditions until true
            James Newton, ACP Level 3
            Is this because auto-play is enabled? It may be that the CD is played automatically, regardless of whether your Director application is running. Perhaps it would help to explicitly eject the CD if the wrong number of tracks is present.
            • 3. Re: testing for conditions until true
              Opera Rat Level 1
              Yes, a combination of your ideas would be good. If the incorrect CD is in the drive than eject it and pop up and error box. If there is an ok and cancel button on the alert box than what if they just hit cancel and still have the wrong CD in the drive? I tried to run Mike's code and even after the correct CD is in the dirve the alert box is there. I think the reason for this came to me in a dream. The CD must be closed and then re-detected before it test for the number of tracks. That is why it would sometimes play the cd outside of director with no other cd program open. Protecting a program from all kinds of error possibilities is just as hard as everything else.
              • 4. Re: testing for conditions until true
                Level 7
                Yeah the code I put in will always send the alert once. You can put the
                whole thing inside of another if statement to avoid it if the correct
                disk is in already:

                if dmm_CDExtGetTotalTracks() <> 4 then
                repeat while true
                if dmm_CDExtGetTotalTracks() <> 4 then
                alert "Please insert correct CD"
                else
                playCD
                exit repeat
                end if
                end repeat
                end if