5 Replies Latest reply on Feb 2, 2008 12:57 AM by KenSevens20

    Lingo if boolean problem

    KenSevens20
      I've got a simple director problem that should be very easy to solve.

      I've got a program that allows the user to place 2 sprites on to 2 targets. The 2 sprites are barrels, and the 2 targets are podiums. Everything works fine, apart from one thing. I have a property called podium1full, and i want to check whether the value of this property is true or false. This will tell the program whether a barrel is already placed on the podium or not when the user tries to put a 2nd barrel on a podium that already has a barrel.

      The full script is in this e-mail below. I have included the director file as an attachment. I would be very grateful if you could please help me out with this.
      Basically, if I try to put sprite(5) on to podium1 when sprite(4) is already on it, the program puts sprite(5) on podium1, despite the fact that I've got an if boolean statement to stop that happening.

      Thanks.

      Thor Putnis (MSc Creative Tech)



      property podium1full -- is podium one full or empty?
      property podium2full -- is podium two full or empty?


      on mouseDown me

      if sprite(4).loc = point (141,550) then
      if sprite(5).loc = point (641,550) then
      set podium1full = FALSE
      set podium2full = FALSE
      end if
      end if

      -- This section of the script checks whether both barrels have been reset recently.
      -- If they have, make sure that the program knows that both podiums are empty when the mouse is pressed down on a barrel


      end mouseDown

      on mouseUp me


      if sprite(4).moveableSprite = TRUE then -- this line checks that the barrel has not been put on a podium
      if sprite(4).locV<(340) then
      if sprite(4).locV>(45) then
      if sprite(4).locH<(265) then
      if sprite(4).locH>(0) then -- these for lines check if the left hand barrel is anywhere near the left podium
      if podium1full = FALSE then -- this line is supposed to check whether the podium is full, but it does not work. Why?

      sprite(4).loc = point (141,171) -- After all the checks have been done, this line places the barrel into place on the podium
      set podium1full = TRUE -- Once the podium is full, set the property value to full
      sprite(4).moveableSprite = FALSE -- This line locks the barrel into place

      else


      sprite(4).loc = point (141,550) -- If the podium is full, this line places the barrel back into its start position

      end if
      end if
      end if
      end if
      end if

      end if



      -- the next section of code is exactly the same as above, except this is for the right barrel on the left podium.

      if sprite(5).moveableSprite = TRUE then
      if sprite(5).locV<(340) then
      if sprite(5).locV>(45) then
      if sprite(5).locH<(265) then
      if sprite(5).locH>(0) then
      if podium1full = FALSE then

      sprite(5).loc = point (141,171)
      set podium1full = TRUE
      sprite(5).moveableSprite = FALSE

      else

      sprite(5).loc = point (641,550)
      end if
      end if
      end if
      end if
      end if
      end if


      -- this is the script for the left barrel on the right podium

      if sprite(4).moveableSprite = TRUE then
      if sprite(4).locV<(291) then
      if sprite(4).locV>(55) then
      if sprite(4).locH<(766) then
      if sprite(4).locH>(516) then
      if podium2full = FALSE then

      sprite(4).loc = point (641,171)
      set podium2full = TRUE
      sprite(4).moveableSprite = FALSE

      else

      sprite(4).loc = point (141, 550)
      end if
      end if
      end if
      end if
      end if
      end if

      -- this is the script for the right barrel on the right podium

      if sprite(5).moveableSprite = TRUE then
      if sprite(5).locV<(291) then
      if sprite(5).locV>(55) then
      if sprite(5).locH<(766) then
      if sprite(5).locH>(516) then
      if podium2full = FALSE then

      sprite(5).loc = point (641,171)
      set podium2full = TRUE
      sprite(5).moveableSprite = FALSE

      else

      sprite(5).loc = point (641,550)
      end if
      end if
      end if
      end if
      end if
      end if


      end

        • 1. Re: Lingo if boolean problem
          KenSevens20 Level 1
          i've uploaded my director file as a zip file, and can be accessed at http://homepage.mac.com/putnis/thor/boolean_problem.zip

          Thanks in advance
          • 2. Re: Lingo if boolean problem
            Level 7
            To be honest Ken, your code can be greatly simplified by using a
            different approach. Try this out. Make a new director movie, with just
            your 2 barrel cast members and your 2 podium cast members. Place them on
            the stage. They don't have to go in any particular sprite channel, but
            the podium sprites MUST come after the barrel sprites.

            Attach this to the barrel sprites (watch for the unintended line breaks
            introduced by the reader).

            -- Start of Barrel sprite script --
            property spriteNum, pStartingLoc, pPodiumSprites

            on beginSprite me

            sprite(spriteNum).moveablesprite = true
            pStartingLoc = sprite(spriteNum).loc
            pPodiumSprites = []

            end

            on mouseUp me

            repeat with i = 1 to pPodiumSprites.count
            if sprite(pPodiumSprites ).pPodiumOccupied = spriteNum then
            sprite(pPodiumSprites
            ).pPodiumOccupied = 0
            end repeat

            isIntersecting = 0

            repeat with i = 1 to pPodiumSprites.count
            if sprite(spriteNum).rect.intersect(sprite(pPodiumSprites ).rect)
            <> rect(0, 0, 0, 0) then
            isIntersecting = pPodiumSprites

            exit repeat
            end if
            end repeat

            if isIntersecting then
            if sprite(isIntersecting).pPodiumOccupied then
            sprite(spriteNum).loc = pStartingLoc
            else
            sprite(isIntersecting).pPodiumOccupied = spriteNum
            sprite(spriteNum).loc = sprite(isIntersecting).loc
            end if
            else
            sprite(spriteNum).loc = pStartingLoc
            end if

            end

            on registerPodiumSprite me, whichSprite

            pPodiumSprites.add(whichSprite)
            if sprite(spriteNum).locZ <= whichSprite then sprite(spriteNum).locZ
            = whichSprite + 1

            end

            -- End of Barrel sprite script --


            Attach this to the podium sprites (watch for the unintended line breaks
            introduced by the reader).

            -- Start of podium sprite script
            property spriteNum, pPodiumOccupied

            on beginSprite me
            sprite(spriteNum).moveablesprite = false
            pPodiumOccupied = false
            sendAllSprites(#registerPodiumSprite, spriteNum)
            end
            -- end of podium sprite script


            It may require some tweaking, but I think it is a lot more straight
            forward. I can send you my sample movie if you prefer.



            • 3. Lingo if boolean problem
              Chunick Level 3
              DaveC, just to let you know that if people are accessing it from the Adobe forum then the line below gets messed up:
              if sprite(pPodiumSprites[ i ]).pPodiumOccupied = spriteNum then

              because [ i ] is interpreted as the start of an italics tag.

              for simplicity the below code can be changed:
              repeat with j = 1 to pPodiumSprites.count
              if sprite(pPodiumSprites[j]).pPodiumOccupied = spriteNum then
              sprite(pPodiumSprites[j]).pPodiumOccupied = 0
              end repeat

              to this:
              repeat with j in pPodiumSprites
              if sprite(j).pPodiumOccupied = spriteNum then
              sprite(j).pPodiumOccupied = 0
              end repeat

              and the same could be done with the other repeat loop below that one. If one wants to use the repeat loop to loop through a list then it's best to get the count of the list before the loop. Getting the count each iteration will be slower, ie.:

              cnt = pPodiumSprites.count
              repeat wtih j = 1 to cnt
              -- whatever code here
              end repeat
              • 4. Re: Lingo if boolean problem
                Level 7
                I see, that way doesn't call the count function with each iteration of
                the loop. Cool

                And I guess [j] works better on the Adobe forum because it isn't a HTML
                tag so the browser displays it properly as text?

                Chunick wrote:
                > DaveC, just to let you know that if people are accessing it from the Adobe
                > forum then the line below gets messed up: if sprite(pPodiumSprites because [ i
                > ] is interpreted as the start of an italics tag. for simplicity the below code
                > can be changed: repeat with j = 1 to pPodiumSprites.count if
                > sprite(pPodiumSprites[j]).pPodiumOccupied = spriteNum then
                > sprite(pPodiumSprites[j]).pPodiumOccupied = 0 end repeat to this: repeat with
                > j in pPodiumSprites if sprite(j).pPodiumOccupied = spriteNum then
                > sprite(j).pPodiumOccupied = 0 end repeat and the same could be done with the
                > other repeat loop below that one. If one wants to use the repeat loop to loop
                > through a list then it's best to get the count of the list before the loop.
                > Getting the count each iteration will be slower, ie.: cnt =
                > pPodiumSprites.count repeat wtih j = 1 to cnt -- whatever code here end repeat
                >
                • 5. Re: Lingo if boolean problem
                  KenSevens20 Level 1
                  Ok, i've sorted out the problem with the code that I've got. I just changed the property values to &quot;global&quot;. That way my code that I've got works fine. I can't believe that I didn't see this problem myself before. I have definitely learnt some new coding techniques from your posts, so for that, I would like to thank you both for replying.

                  Cheers!