Thursday, 5 March 2009

Repeat Loops And Redundant Attribute Declaration

The Repeat loop in the image below iterates 20 times and creates a column of particles - the counter increments the Y height by 1 unit each time. In Python, I'd normally create the array for the resultant positions and the counter itself outside of the loop and, for a while, this is how I constructed loops in ICE:



It turns out that ICE is much cleverer than that. Put plainly, you can 'Get' an attribute before you 'Set' an attribute. I know this doesn't sound too earth shattering but it confused me for a while. In a conventional scripting language you can't usually work with a variable/attribute before you've declared it. In ICE, however, you can. If I remove the initial Set Data on both the Counter and the Array in the tree:



The tree still works even though, ostensibly, for the very first iteration of the loop it looks like you're requesting Counter and Array before you've assigned any value to them. It seems that ICE pre-processes attributes before the tree is evaluated and initialises them to a default value - in this case on the very first iteration of the loop ICE knows that array is an array of 3D vectors and inserts a default vector value of (0,0,0) and Counter is a scalar and inserts 0.

Saves a lot of unnecessary tree clutter.

No comments:

Post a Comment