Jump to content
Sign in to follow this  
lulu01

While loop won't stop?

Recommended Posts

Hey,

I'm trying to understand the while loop in Houdini VEX using a solver, but having  trouble understanding it.

I've got 1 point connected to a solver, with a point wrangle inside using this code:

while(@P.x <= 10)
    {
        @P.x += .1;
        
        if(@P.x >= 10) {
        break;
        }
    }

 

its nothing fancy just trying out the basics, but for some reason the loop won't stop after the condition is met.
Neither the breaks help, what I'm doing wrong?

I also got this one below, but in this one the code makes the point slow down after the condition is met?
 

int i = 0;
    
while(i <= 10)
    {
        @P.x += .1;
        i++;
        
    if(@P.x >= 10.0) {
        break;
        }
    }

Share this post


Link to post
Share on other sites

I'm not a coding expert or even Houdini expert but I think the solver works on per frame basis. The While is more appropriate to repeating your action in coding POV.

so my simple example works because it evals each frame then do something....while if you use a While who knows what it's trying to do per frame with a While ? I can't explain it....let some other guru better explain it.

vu_simplesolver.hiplc

  • Like 1
  • Downvote 1

Share this post


Link to post
Share on other sites

you'll need to provide some more info or file as 

while(@P.x <= 10)    {
        @P.x += .1;
}

seems to work perfectly fine when executed on a single point in SOPs, what's your solver setup?

while_loop.hip

  • Thanks 1

Share this post


Link to post
Share on other sites
4 hours ago, anim said:

you'll need to provide some more info or file as 


while(@P.x <= 10)    {
        @P.x += .1;
}

seems to work perfectly fine when executed on a single point in SOPs, what's your solver setup?

while_loop.hip

ah I see where I gone wrong now...I did set up my basic test like yours, with a solver tho...and thought it didn't work....but it DID, it just didn't show the steps in between like my setup using the IF.

Anyway, it could be completely different the the OP's setup tho.

Edited by Noobini

Share this post


Link to post
Share on other sites
12 hours ago, Noobini said:

I'm not a coding expert or even Houdini expert but I think the solver works on per frame basis. The While is more appropriate to repeating your action in coding POV.

so my simple example works because it evals each frame then do something....while if you use a While who knows what it's trying to do per frame with a While ? I can't explain it....let some other guru better explain it.

vu_simplesolver.hiplc

Indeed a While loop does not work in this example, thanks for pointing that out!

Now that I know this the next step for my little experiment is to change an Element in an array, just like I change the @P.x value within a solver.

The goals is to change the third element in the array, by subtracting 1 per loop. How would this work?
I already tried a Push, Append, insert function. But some I can't specify the array element, or I just add a new element to the array, and does not loop the action.
I'm clearly doing something wrong here, please someone tell me the logic behind this problem ;)

 

 

i[]@array = {0,1,2,3};                    //_Array

string dir = chs('dir');                     //_input
float steps = chf("steps");              //_input

i@check = @array[3];

if(dir == 'F' && @P.x <= steps)      //_Condition
    {
        @P.x += .1;                         //_Action
        @array[3] -= 1;                   //_Substract element per loop???
    } 

Change_element.hipnc

Edited by lulu01

Share this post


Link to post
Share on other sites
17 minutes ago, lulu01 said:

Indeed a While loop does not work in this example, THX!
Now that I know this, the next step for my little experiment is to change an Element in an array, just as i change the @P.x value within a solver.

 

i[]@array = {0,1,2,3};              //_Array

string dir = chs('dir');            //_input
float steps = chf("steps");         //_input

i@check = @array[3];

if(dir == 'F' && @P.x <= steps)     //_Condition
    {
        @P.x += .1;                 //_Action
        @array[3] -= 1;             //_substract element???
    } 

mmm...I think it works tho as anim pointed out, the reason it's hard to 'detect' is because it jumps to the end condition straight away, while for my IF example you could see each frame/step more easily.

unless I'm still not clear on your set up ?

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, lulu01 said:

Indeed a While loop does not work in this example, thanks for pointing that out!

Now that I know this the next step for my little experiment is to change an Element in an array, just like I change the @P.x value within a solver.

The goals is to change the third element in the array, by subtracting 1 per loop. How would this work?
I already tried a Push, Append, insert function. But some I can't specify the array element, or I just add a new element to the array, and does not loop the action.
I'm clearly doing something wrong here, please someone tell me the logic behind this problem ;)

 

 

i[]@array = {0,1,2,3};                    //_Array

string dir = chs('dir');                     //_input
float steps = chf("steps");              //_input

i@check = @array[3];

if(dir == 'F' && @P.x <= steps)      //_Condition
    {
        @P.x += .1;                         //_Action
        @array[3] -= 1;                   //_Substract element per loop???
    } 

Change_element.hipnc

You should set i[]@array before solver, otherwise it's getting the same value each sub step in the solver sop

Change_element_01.hipnc

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×