6 Replies Latest reply on Aug 13, 2007 1:18 PM by Newsgroup_User

    Trouble with intersects

    andy_scot
      When i try to set up code for an interest it will not work correctly.
      I am trying to make it that when sprite 45 intersects sprite 29 that there will be a value removed from a field called pages

      i have tried writing it as

      if sprite 45 intersects sprite 29 THEN
      gvpages = gvpages - 1
      put gvpages into field "pages"
      end if

      can anyone fix that code for me so it will remove 1 from the number of pages when they intersect?
      Thanks, andy
        • 1. Re: Trouble with intersects
          Level 7
          What does the rest of the behavior look like? Or is this a movie script?
          Are you declaring gvpages as a property or a global variable?

          --
          Rob

          ___________
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412.243.9119
          • 2. Re: Trouble with intersects
            andy_scot Level 1
            ive declared the gvpages as a global at the top of the behaviour, i then set the boundaries for the sprite and then added the code previously posted
            • 3. Re: Trouble with intersects
              Level 7
              What is happening now? Does the field "pages" contain anything? Do you
              get an error message? Is this "if" statement in an on enterFrame me
              function?

              I need more to go on before I can suggest a solution.
              --
              Rob

              ___________
              Rob Dillon
              Adobe Community Expert
              http://www.ddg-designs.com
              412.243.9119
              • 4. Trouble with intersects
                andy_scot Level 1
                global gvnumbers, gvpages

                on beginSprite me

                pSprite = sprite(me.spritenum)
                pleftBound = 183
                prightBound = 1340
                ptopBound = 100
                pbottomBound = 850
                pMove = 5
                end
                on exitframe me
                pSprite.loch=pSprite.loch+pMove

                if pSprite.loch > prightBound then
                pMove=pMove*-1

                end if

                if pSprite.loch < pleftBound then
                pMove=pMove*-1

                end if
                on mousedown me
                if sprite 45 intersects 29 then

                gvpages = gvpages - 1
                put gvlives into field "pages"

                end if





                end
                • 5. Re: Trouble with intersects
                  andy_scot Level 1
                  also yes the field pages contains the value 14 at the start so, i just want it so that when the sprite intersects the other one then the number of pages is decreased by one, thanks
                  • 6. Re: Trouble with intersects
                    Level 7
                    Try something like the behavior below. You need to declare property
                    variables for each of the variables that you are defining in the
                    beginSprite function. If you don't do this, then the values won't exist
                    outside that function.

                    I also added another property variable, "movingLeft", this is a boolean
                    variable that you'll need to get your sprite to move properly.

                    ----------------
                    global gvnumbers, gvpages

                    property
                    pSprite,pleftBound,prightBound,ptopBound,pbottomBound,pMove,movingLeft

                    on beginSprite me

                    pSprite = sprite(me.spritenum)
                    pleftBound = 100
                    prightBound = 700
                    ptopBound = 100
                    pbottomBound = 550
                    pMove = 5
                    movingLeft = false
                    end
                    on exitframe me
                    pSprite.loch=pSprite.loch+pMove

                    if pSprite.loch > prightBound AND movingLeft = false then
                    movingLeft = true
                    pMove=pMove*-1

                    end if

                    if pSprite.loch < pleftBound AND movingLeft then
                    movingLeft = false
                    pMove=pMove*-1

                    end if

                    end
                    ---------------

                    --
                    Rob

                    ___________
                    Rob Dillon
                    Adobe Community Expert
                    http://www.ddg-designs.com
                    412.243.9119