11 Replies Latest reply on Mar 4, 2009 4:49 AM by Newsgroup_User

    Counting globals?

      I have a question that is potentially difficult to put into words.. but here goes!

      I have a project, with 10 boxes for employee positions, and 15 boxes with employee names. What I want is a counter that shows a number for how many positions are taken. At the moment, when an employee name intersects a position, that name stays attached to that position. So I could have a global saying that when an employee intersects a position, set that global to true. But then is there a piece of script that counts how many of these globals are true, therefore giving me a number for how many positions are taken? Or is there an easier way of doing this?

      Thanks very much :)
        • 1. Re: Counting globals?
          Level 7
          This is a multi-part message in MIME format.
          --------------040001080009090400040007
          Content-Type: text/plain; charset=ISO-8859-1; format=flowed
          Content-Transfer-Encoding: 7bit

          You could have another global which just counts the number of positions
          have been set. WHenever you add a persons name to a position, increment
          this new global by 1... if you remove a name, remove one.

          --------------040001080009090400040007
          Content-Type: message/rfc822;
          name="Attached Message"
          Content-Transfer-Encoding: 7bit
          Content-Disposition: inline;
          filename="Attached Message"

          Path: forums.macromedia.com!not-for-mail
          From: "Rich Bagnall" <webforumsuser@macromedia.com>
          Newsgroups: macromedia.director.lingo
          Subject: Counting globals?
          Date: Tue, 3 Mar 2009 17:42:22 +0000 (UTC)
          Distribution: macromedia
          Message-ID: <gojq5u$c5f$1@forums.macromedia.com>
          NNTP-Posting-Host: p01webapp11.macromedia.com
          X-Trace: forums.macromedia.com 1236102142 12463 10.172.12.84 (3 Mar 2009 17:42:22 GMT)
          X-Complaints-To: support@macromedia.com
          NNTP-Posting-Date: Tue, 3 Mar 2009 17:42:22 +0000 (UTC)
          Xref: forums.macromedia.com macromedia.director.lingo:235977

          I have a question that is potentially difficult to put into words.. but here
          goes!

          I have a project, with 10 boxes for employee positions, and 15 boxes with
          employee names. What I want is a counter that shows a number for how many
          positions are taken. At the moment, when an employee name intersects a
          position, that name stays attached to that position. So I could have a global
          saying that when an employee intersects a position, set that global to true.
          But then is there a piece of script that counts how many of these globals are
          true, therefore giving me a number for how many positions are taken? Or is
          there an easier way of doing this?

          Thanks very much :)


          --------------040001080009090400040007--
          1 person found this helpful
          • 2. Re: Counting globals?
            James Newton, ACP Level 3
            Have you looked at Lingo lists yet?

            aList = []
            aList.add("some data")
            put aList
            -- ["some data"]
            aList.addAt(1, "first place")
            put aList
            -- ["first place", "some data"]
            anotherList = aList
            aList.deleteAt(2)
            put anotherList
            -- ["first place"] -- you changed aList, but anotherList has changed too.

            Lists are like magic maps. There's a whole set of methods that you can use. There are linear lists and property lists. Explore.
            • 3. Re: Counting globals?
              Thank you. I think Mike's option would probably be simpler. I have some basic experience with globals, but none with lists!

              Mike, how would I go about doing this? Would I still need a global for each job position?

              Rich
              • 4. Re: Counting globals?
                Level 7
                There are as many ways of doing this as there are programmers.
                Actually, openspark's method is far superior to mine for many reasons...
                using lists is one of the most powerful things that Director can do
                really well.

                But you could do it with a unique global for each position, and another
                global for the count.

                Or the list method would be cleaner. Make a moviescript like this:

                --snip--
                global gPositionList

                on startMovie
                gPositionList=[:]
                end

                on setPosition(vNum,vName)
                gPositionList["pos"&vNum]=vName
                end

                on getPosition(vNum)
                if not voidP(gPositionList["pos"&vNum]) then
                return gPositionList["pos"&vNum]
                end if
                end

                on removePosition(vNum)
                gPositionList.deleteProp("pos"&vNum)
                end

                on getPositionCount me
                return gPositionList.count
                end
                --snip--

                That should be everything you need. When you want to set the name of a
                person at position 3, you would do this:

                setPosition(3,"mike")

                Then you can find out who is there:

                put getPosition(3)
                -- "mike"

                And you can see if there is no one there, since it will return void:

                put getPosition(1)
                -- <void>

                And you know how many positions are taken like this:

                put getPositionCount()
                -- 1
                • 5. Re: Counting globals?
                  Level 7
                  Oh yeah. You can remove someone from a position like this:

                  removePosition(3)
                  1 person found this helpful
                  • 6. Re: Counting globals?
                    I think I will stick with the globals, as the lists have gone right over my head! I also think I might over complicated the situation.

                    What I've done is said that if any name intersects position 1 then set gPosition1 as true etc. Therefore I have 10 globals (one for each position) which are either true or false. So I need a number 0, that will increment by 1 for each global that is true. Surely this cannot be difficult? But I can't get it to work :S ??
                    • 7. Re: Counting globals?
                      Level 7
                      Declare another global with a name like gPositionCount. Set it to 0.
                      Whenever you add a position (by setting gPositionx=TRUE), then follow
                      that command with something like this:

                      gPositionCount=gPositionCount+1

                      And if you have someone leave a position, then delete one.
                      • 8. Re: Counting globals?
                        Thanks. And how do I display that on the stage as a number? Nearly there!
                        • 9. Re: Counting globals?
                          Level 7
                          "I think I will stick with the globals, as the lists have gone right
                          over my head!"

                          A list can be held in a global variable, a local variable or a property.
                          Lists and globals are not mutually exclusive.

                          Don't sell yourself short. Understanding how to use lists is not beyond
                          you and will lead to you becoming a better programmer.
                          • 10. Re: Counting globals?
                            Yeah I will look into them, I have a massive Director book but its at my other house :( Do you know how to display the gPositionCount on stage as a number?
                            • 11. Re: Counting globals?
                              Level 7
                              Make a #text member that is on stage with this script:

                              global gPositionCount

                              on enterFrame me
                              if voidP(gPositionCount) then gPositionCount=0
                              sprite(me.spriteNum).member.text=string(gPositionCount)
                              end
                              1 person found this helpful