This content has been marked as final. Show 11 replies
This is a multi-part message in MIME format.1 person found this helpful
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
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.
From: "Rich Bagnall" <firstname.lastname@example.org>
Subject: Counting globals?
Date: Tue, 3 Mar 2009 17:42:22 +0000 (UTC)
X-Trace: forums.macromedia.com 1236102142 12463 10.172.12.84 (3 Mar 2009 17:42:22 GMT)
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
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 :)
Have you looked at Lingo lists yet?
aList = 
-- ["some data"]
aList.addAt(1, "first place")
-- ["first place", "some data"]
anotherList = aList
-- ["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.
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?
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
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:
if not voidP(gPositionList["pos"&vNum]) then
on getPositionCount me
That should be everything you need. When you want to set the name of a
person at position 3, you would do this:
Then you can find out who is there:
And you can see if there is no one there, since it will return void:
And you know how many positions are taken like this:
Oh yeah. You can remove someone from a position like this:1 person found this helpful
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 ??
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:
And if you have someone leave a position, then delete one.
Thanks. And how do I display that on the stage as a number? Nearly there!
"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.
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?
Make a #text member that is on stage with this script:1 person found this helpful
on enterFrame me
if voidP(gPositionCount) then gPositionCount=0