13 Replies Latest reply on May 26, 2013 11:27 AM by GRAMOPHONE

    Repeat with sprite...

    GRAMOPHONE Level 1

      Hi,

      I'm trying to get the highest and the next to the highest locV on sprites from 509 to 518, but I don't have an idle idea on how to write this script.

      These sprites are moving up and down and I want to get the highest and the next to the highest. I have also noticed that the highest the location (locV) the smallest the number. So what we are looking here is the smallest and the next to the smallest locV numbers.

      Please, help me.

      I have used spriteNum, sprite, channel, etc with reapeat with, but nothing works.

        • 1. Re: Repeat with sprite...
          James Newton, ACP Level 3

          In the Message window, type:

           

          go movie "http://nonlinear.openspark.com/tips/sprites/highestSprite.dir"

           

          Does that give you your answer?

          • 2. Re: Repeat with sprite...
            GRAMOPHONE Level 1

            Hi James,

            I assume this is the script that gets the highest and the next to highest sprite.

             

            on getHighestSprite(aStart, aEnd)

              vSpriteList = [:]

             

              repeat with ii = aStart to aEnd

                vSprite = sprite(ii)

                vLocV = vSprite.locV

                vSpriteList.addProp(vLocV, vSprite)

              end repeat

             

              vSpriteList.sort()

             

              vResult = [:]

              vResult[#highest] = vSpriteList.getAt(1)

              vResult[#nextHighest] = vSpriteList.getAt(2)

             

              return vResult

            end getHighestSprite

             

             

            Now the big question is how can I incorprate the sprite numbers that I want to use? Do I have to attach the behavavior to the sprite? I already have a behavior attached to the sprites that make then move up and down according to a sound.

            • 3. Re: Repeat with sprite...
              Sean_Wilson Adobe Community Professional

              While I'm sure James will answer for himself, what you posted looks to me like a movie handler - so place it in a movie script. At any point in time where you want the highest etc. sprite/s, call the handler with (in your case):

              lSprites = getHighestSprite(509, 518)
              highestSpriteNum = lSprites[#highest]
              nextHighestSpriteNum = lSprites[#nextHighest]
              

              You now have the numbers of the 2 sprites you're interested in. Do what you will with those sprites ...

              • 4. Re: Repeat with sprite...
                GRAMOPHONE Level 1

                Hi Sean,

                Sorry about my Lingo little knowledge, but how can I combine the two script? Yours alone, I believe it's not complete. Can this work without the repeat with?

                I tested it and it doesn't work.

                 

                Thanks again for your help.

                • 5. Re: Repeat with sprite...
                  Sean_Wilson Adobe Community Professional

                  You say

                  I tested it and it doesn't work.

                  Please explain what doesn't work.

                   

                  Did you create a #movie script and add this handler, or paste it into an existing movie script (Ctrl + Shift + U)? Once you've done this you can call the movie script handler from any other piece of code when you need to, passing it parameters of the sprite span you want to check (in your case apparently 509 to 518) - like I suggested in my previous post.

                   

                  Can this work without the repeat with?

                  I'm sorry, but I don't understand what you're asking with the above question. There is a 'repeat with...' loop in the code James provided. This is the easiest way to check a contiguous span of sprite numbers, just like you asked for in your initial post.

                  • 6. Re: Repeat with sprite...
                    GRAMOPHONE Level 1

                    I'm sorry bugging you again, upsetting your patience, but this is what I did:

                     

                    I created a movie script this way:

                     

                    on mySprites

                      lSprites = getHighestSprite(105, 114)

                      highestSpriteNum = lSprites[#highest]

                      nextHighestSpriteNum = lSprites[#nextHighest]

                      put highestSpriteNum

                      put nextHighestSpriteNum

                    end

                     

                     

                    I put mySprites handle on a frame, play the audio the moves up and down the sprites

                    and this is what I receive:

                    -------------------------------------------------------

                    Script error: Handler not define

                    lSprites = getHighestSprite(509, 518)

                    #getHightestSprite

                    -------------------------------------------------------

                     

                    I have to admit I'm the stupidest guy at Lingo in the whole universe. OH, I'm on Director MX2004. What am I doing wrong here or what is it that I'm not doing?

                    • 7. Re: Repeat with sprite...
                      Sean_Wilson Adobe Community Professional

                      The error message you posted means that the handler 'getHighestSprite' that you posted back in your comment #3 isn't defined in a movie script. Did you try the key combination I suggested for opening a movie script window? Do you understand the difference between a movie script and a score/behavior script?

                       

                      Once you have understood what a #movie script is and how to start one (or change the type of an open empty script window from Behavior to Movie) then you can post in the handler James provided you with.

                      • 8. Re: Repeat with sprite...
                        GRAMOPHONE Level 1

                        I may be a moron, but I at least I know the difference between a movie script and a behavior and I created this as movie script:

                         

                        on getHighestSprite

                          lSprites = getHighestSprite(509, 518)

                          highestSpriteNum = lSprites[#highest]

                          nextHighestSpriteNum = lSprites[#nextHighest]

                          put highestSpriteNum

                          put nextHighestSpriteNum

                        end

                         

                        I run the program, playing the sound that move those  sprites up and down and I executed the script from the message window and now I received this

                        pop window:

                         

                        Warning! The current movie has used all of director's main memory.

                        Please, save any changes immediatly.

                         

                        I have 16GB of RAM and this never happened before.

                         

                        I called the handler from a frame behavior script and the same thing.

                         

                        I can sense that you are tired and sick of this. I'm sorry, and if you think I'm not understanding what you are trying to tell me, just forget it, and really appreciate your help and regret to make waste your time on this.

                        • 9. Re: Repeat with sprite...
                          Sean_Wilson Adobe Community Professional

                          The handler you need to copy-and-paste into your movie script is the one you posted earlier:

                          on getHighestSprite(aStart, aEnd)
                            vSpriteList = [:]
                          
                            repeat with ii = aStart to aEnd
                              vSprite = sprite(ii)
                              vLocV = vSprite.locV
                              vSpriteList.addProp(vLocV, vSprite)
                            end repeat
                          
                            vSpriteList.sort()
                          
                            vResult = [:]
                            vResult[#highest] = vSpriteList.getAt(1)
                            vResult[#nextHighest] = vSpriteList.getAt(2)
                          
                            return vResult
                          end getHighestSprite
                          

                          My apologies if I came across as insulting - I have no idea what you do or don't know!

                          • 10. Re: Repeat with sprite...
                            GRAMOPHONE Level 1

                            Thank you, guys, but I give up. There's no way this works. So the best thing I can do is forget about this project before I end up in a nuthouse.

                            Thanks again.

                            • 11. Re: Repeat with sprite...
                              Mister MUX Level 2

                              The clue as to why you ran out of memory is found in the first two lines of your code.

                               

                              on getHighestSprite

                                lSprites = getHighestSprite(509, 518)

                               

                              Your function calls itself (known as recursion). I doubt you intended to write a recursive function. A recursive function must eventually return a non-recursive value. Otherwise it keeps calling itself, which leads it call itself again, and again and again until you run out of memory. It's kind of like following (too literally) the directions on the shampoo bottle  "lather, rinse, repeat". Your shower would never end.

                              • 12. Re: Repeat with sprite...
                                Sean_Wilson Adobe Community Professional

                                So how about providing a version of your file? Send me a Private Message with your email address and I'll give you somewhere to send it.

                                • 13. Re: Repeat with sprite...
                                  GRAMOPHONE Level 1

                                  Hi Sean,

                                  I sent you you the file. Have you had any chance to take a look at it?

                                   

                                  Thanks

                                   

                                  Brian