[chuck-users] Doing something to all members of a class?

David Powers cyborgk at gmail.com
Tue Mar 13 17:36:40 EDT 2007


On 3/12/07, Kassen <signal.automatique at gmail.com> wrote:
> Hi, list!
>
> I'm having a bit of a issue with classes.
>
> Say I have a class that has a member that's simply a integer used for
> counting something.
>
> I'll have a few instances (ten or so) and they will all be counting their
> own little thing on their own. So far so good. Now something happens and I'd
> like to reset all the counters to zero after which they should be
> independant again.
>
> How to go about this in a efficient way?

Hi Kassen,

I could be wrong, but I think you do the following:
1. Give the class a reset method
2. Every time you create an instance, add the instance to an array
3. To reset, run your reset method on all instances contained in the array

A more automated way, though I'm not entirely sure if/how it would
work in ChucK:
1. Give the class a reset method
2. Give the class a static array property
3. In the class initialization code, add objects to the static array
when they are initialized
4. Add a static reset method, that runs the object reset method from
(1) on each instance of the static array.
5. Run the static reset method to reset everything while you are ChucK-ing..

***Warning: most OOP I do is in Flash Actionscript 2.0 right now,
which is far from a good programming language. Take this with a grain
of salt, but it should theoretically work to the best of my knowledge.


More information about the chuck-users mailing list