Passing values to iterated objects

benoitlahoz's picture

Hi !

I'm trying to make a series of random X-scaled planes, and I would like the planes to be joined on their edges.

These planes would be translating on X, all joined.

So I would have to pass width and position from one plane to another, but I can't manage to find how to do with an iterator, as I want the number of planes to be a variable... and the whole comp to be... well... as elegant as possible...

I guess this must be quite simple, but passing values from an iteration to another is out of my competences for the moment...

Does any of you have an idea ?

Thanks in advance !

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

usefuldesign.au's picture
Re: Passing values to iterated objects

This composition was done with two Javascript loops and one iterator. It sounds conceptually kind of similar to what you want. Creates the data in one JS patch and passing it as an array to another JS patch for processing and then iterating the resultant sprites.

Passing values from one iterator to another is a matter of setting up a Queue patch (or JS Patch which references the Iterator Variables Index to set a value in Array) and publishing it out of the Iterator (10.6+ only).

benoitlahoz's picture
Re: Passing values to iterated objects

Thanks a lot ! I had already seen this great comp.

The thing is that, as I'm translating all the planes on the X axis (from 1.2 to -1.2 approximately), I would like the disapeared plane to come exactly at the right of the one appearing.

So I guess I need to get the X positions of these two planes (and, well, of all the planes) from the iterator...

But maybe I'm going in the wrong direction with the iterator.

[edit : as a bonus I would like each plane to acquire a new width while is invisible... :-)]

benoitlahoz's picture
Re: Passing values to iterated objects

Well... I guess I'm not really clear on what I want to do... So I'll try to explain, to not abuse with your patience...

  1. A defined number of planes are created...
  2. ... with random width but to fill the screen
  3. These planes are joined by their edges
  4. Images are downloaded (Directory scanner) and each image is applied to one plane
  5. Planes are translated on the X axis from right to left
  6. When a plane disappear (I use a condition on the X position) :
  • the plane acquire a new random width

  • a new image is applied on the plane

  • it is positioned on the X axis exactly at the right of the whole "plane chain"

And this... for each plane...

Wow, a lot of question... I'm thinking about having a defined number of objects but using a structure to "shift" and "push" the planes.

usefuldesign.au's picture
Re: Passing values to iterated objects

I've got a feeling there was a really early developer example that did this but I can't find it. Was a kind of scroller/ticker thing. There's a bunch of ways to implement something like this none of them trivial so I'm not posting code :-)

If I may offer my view on getting to where you want to be (when you aren't sure what it is):

The first stage in coding a solution is framing your specification for what it needs to do — carefully. Then break it down until you have some definitions for how sprites or whatever appear where and when they do. Then write some maths equations and conditions. Do all this away from your Mac, that helps a lot I find! Draw diagrams etc really nut it out first, it makes the coding much easier with clear goals and rules+logic already determined to some good extent.

(You have started on this but need to go further to actually define the rules and equations explicitly)

Also iterate. Start out with a humble version and add features. Writing your spec down first helps to patch it from the start in a way that will allow the features you want to be added without re-patching the whole code from scratch.

This may seem obvious but I feel like it's worth saying because quite often members post an unclear concept of what they want which is even harder to guess by someone unfamiliar with their desired goals.

benoitlahoz's picture
Re: Passing values to iterated objects

Thank you ! :-)

Well, I think I know quite well what I want to do (my problem is more... to explain correctly), but it is always good to hear a precious advice !

I guess I have to focus on each plane as a separate object BEFORE thinking about sharing parameters... You're right : a "mindmapping" time won't be useless ! :)