Jump to content

While loop won't stop?


lulu01

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;
        }
    }

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...