for() {for(OutOfRange!!!Why?)}

Hi there,
My index always seems to be going out of range and I am unsure why.

I am setting a tweened path for an array of transforms (coins),
I first gather the first 3, the second 3 and so on members of another array (nodes) until nodes limit is hit (a number divisible by 3),
and then I am creating the tween.

The error occurs at line 7 of the second for loop. The index is out of range, after the first run thru. It makes no sense to me as to why.
Thanks

	// Update is called once per frame
	void jpCoinsWonPlayExplosion () {
		///create and play the coins tweens/
		print("coins won explosion " + Time.time);
		coinTweens = new Tweener[coins.Length];
		coinsLength = coins.Length;
		nodesPos = new Vector3[3];
		
		
		for(int i = 0; i < coinsLength; i++){
			///pass transfrom[] to a transform. needed?			
			///gather the nodes for the path.
			for(int n = 0; n < 3; n++){
				int nodeMember = (i * 3) + n;///here is where it gets tricky. if i >0, I am already retaking taken nodes.not good.
				print("nodeMember " + nodeMember);
				node = nodes[nodeMember];///How do I insure the nodeMember, is always 
				nodesPos[nodeMember] = node.localPosition;	//////!!!!!!!!!STILL GETTING ERROR HEAR. Index Out Of Range.		
			}
			
			print("nodesPos length = " + nodesPos.Length);
			
			coins[i].gameObject.renderer.enabled = true;
			print("coins[i] " + coins[i]);
			// Setup the tween brain using the given path
			coinTweens[i] = HOTween.To(coins[i], tweenTime, new TweenParms()
				.Prop("position", new PlugVector3Path(nodesPos, PathType.Curved)) // Set the PlugVector3Path plugin
				.Ease(EaseType.EaseInExpo) // Set a linear easing
				.AutoKill(false) // Prevent the tween to be auto-killed when it completes
				.Pause(true) // Set the tween in a paused state
				.Loops(7)
			);
			coinTweens[i].Restart();
			if(i == 3)
			return;
			print("coinsTween[i] created i = " + i);
		}
	}

It’s because on the second iteration of the outer loop, nodeMember will start at 3…which is greater than the last index of nodesPos, which has a size of 3 (and thus a last index of 2).

What is the following line trying to accomplish?:

 int nodeMember = (i * 3) + n;///here is where it gets tricky. if i >0, I am already retaking taken nodes.not good.

As gundam said nodeMember will be greater than 3 anytime the i > 1 so at max you will get 4 proper nodes when i = 0 and n = 1, 2 or 3 and when i = 1 and n = 0

It’s for accessing a 1D array in a two dimensional manner. @renman3000, if you’re trying to do what I think you’re trying to do, then nodePos[nodeMember] should be nodePos[n] instead.

Lol. I know what he is trying to do, I was asking him so he would try to explain why he is doing it. So a better solution may be given. Guessing what he is trying to do is both time wasting and futile.

Ah,
so if n == 3, n = 0.

Nice!
I have been racking my head with this for two days. Of course not dedicated, but you get the picture.

Cheers