Hi everyone,
I have a question with a simple code in vex.
I would like increment a index every n frame. For this I use a modulo in condition (if).
My code looks like that:
@Index = 0 ;
if(@Frame%20==0){
@Index +=1;
};
But with this, houdini dont keep value of my increment. For frame between F0 to F19 index =0 for F20 =1 for F21 = 0 for F40 = 1; etc...
If you have any idea, I would like to know.
Thanks everyone !
Increment only 10 Frame with Vex
4803 3 0- BastienPetitTestucci
- Member
- 4 posts
- Joined: Oct. 2018
- Offline
- jerry7
- Member
- 620 posts
- Joined: Nov. 2013
- Online
- BabaJ
- Member
- 2038 posts
- Joined: Sept. 2015
- Offline
But with this, houdini dont keep value of my increment. For frame between F0 to F19 index =0 for F20 =1 for F21 = 0 for F40 = 1; etc...
If you have any idea, I would like to know.
The reason is because your not telling Houdini to 'keep' the previous value. For example, at the Frame numbers 21 to 39 your code doesn't define what @Index value should be. So in Houdini when you have an attribute present but has not been defined with a value, most attributes default to a value of 0. So once you get to Frame 40, your only adding 1 to 0.
When you were at frame 20, it assigned @Index as 1 ONLY when it was at that frame. You have to think of how Houdini works differently since you are thinking values persist. Values only 'persist' if you code it in a way so that they do actually persist. Which is why jerry7 example works (if you change @frame to @Frame).
If your in a situation in which things get too complicated or are hard to manage and you can't think of a way to code for values to 'persist', you might want to learn how to use a solver sop.(your original code would work inside a solver sop, if you wire the nodes right)
Edited by BabaJ - Dec. 20, 2020 16:25:54
- vusta
- Member
- 555 posts
- Joined: Feb. 2017
- Offline
-
- Quick Links