# How to do feedback loops in VEX to create a "Stacking" effect. Also free book generator/placer HDA.

## Recommended Posts

I cannot seem to wrap my head around how to do this so I am asking here. Im looking for a way to "stack" values with VEX. If i simplify it I want to create a point and assign it a random value, then move it that value in the x direction. After that I want to create a second point, give it a new random value and move it that distance + the distance of the first point. The purpose is to create a point generator with random scale values that i can use with LOPs inside of an instancer to place books next to eachother at random scales. I made this in sops and it worked well on a smaller scale but I ended up doing a few thousand books and overloaded my ram. Currently what i have is this.

int iter = chi("Iterations");
float minwidth = chf("Min_Width");
float maxwidth = chf("Max_Width");

for(int i = 0; i < iter; i++){

float currentwidth = fit01(rand(i), minwidth, maxwidth);
float prevwidth = fit01(rand(i-1), minwidth, maxwidth);

vector pos = set(prevwidth+currentwidth/2, 0, 0);

}

My thought process was to create a random value based on the iteration, this random number would be the book width scale value, which is just fitted so i dont get small values. Then to get the previous books width i would subtract the iteration by 1 which successfully returns the same value. Then i create a point and move it by the previous book width + the current book width/2 because i want the point to be centered. However this doesn't work at all because it can only access a single value back.

Also i uploaded the sop book generator below if anyone was interested, its pretty flawed the more that i look at it i should have split it into separate HDAs and also you need to have your coordinates set to Z-up. Heres a demo of it through if anyones interested.

Edited by Latimerias

##### Share on other sites

Hi,

You can use the Solver SOP to accumulate data from the previous frame. Alternatively you can also use a For Loop network in Feedback mode.

• 1

##### Share on other sites

This is what I did in the sops method i attached, is there a way to do this in VEX? I realize i would be better using a while loop probably, because i want to stop once the total distance is greater than the length of the shelf.

Edited by Latimerias

##### Share on other sites

If you want to do that in VEX, you have to use a for loop inside VEX to do the accumulation.

##### Share on other sites
7 hours ago, Latimerias said:

If i simplify it I want to create a point and assign it a random value, then move it that value in the x direction. After that I want to create a second point, give it a new random value and move it that distance + the distance of the first point.

Hi,

You can do this inside a SOP solver like Animatrix mentioned, through a for loop or if statements like what I provided in the example. Essentially you're targeting the last point created then adding a new point based on the last point's position + a new random X value. Also you can control the max distance to make sure the solver doesn't create points beyond a certain distance.

##### Share on other sites

A for each will works as well or better

## Create an account

Register a new account