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

Kassen signal.automatique at gmail.com
Tue Mar 13 20:35:52 EDT 2007


On 3/13/07, David Powers <cyborgk at gmail.com> wrote:
>
>
> 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


Yes, that's exactly what it comes down to.


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


Right! This would be by asigning "this" (the keyword) to the array at the
first location that's not yet used, right? We'd simply make the array quite
large to have headroom for later growth.



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.



No, as far as I understand it now that would work fine and it's actually
quite clever and clean, I think. I think I'll use this method, it will also
make what I'm doing now far easier to extend without having to manually keep
house in some arbitrary spot. I don't like it when things that are that
important to the overall stability have no clear place in the program.


Thanks!

Kas.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20070314/4c8d937a/attachment-0001.htm 


More information about the chuck-users mailing list