Jump to content

VEX help! check if value has changed, then do something


anbt

Recommended Posts

Hello,

I would like to translate this into VEX.
for context, on the first frame, @weight is 0 and becomes not 0 at a specific frame 3, but becomes 0 again at frame 4.
I would like the weight values which changed at frame 3 to stay changed. To get impregnated by the value they had at frame 3

if weight==0 then active==0
but if weight==0 && prevF weight!=0 then active=1

I can't make it work!

Link to comment
Share on other sites

int specificFrame = 3; // Define the specific frame

if (@Frame == specificFrame) {
    @myStoredValue = @weight; // Store the value of @weight at frame 3
}

if (@Frame > specificFrame && @myStoredValue != 0) {
    @weight = @myStoredValue; // Use the stored value for subsequent frames if it's not 0
}

@anbt Just wondering if anything here its Correct  ?? is it working in your Case ?.. :rolleyes:
 

int prevFrame = @Frame - 1;

if (@Frame == 1) {
    // Initialize a custom attribute "impregnated_weight" on the first frame
    @impregnated_weight = 0;
} else if (@Frame == 3) {
    // Store the current @weight in the custom attribute at frame 3
    @impregnated_weight = @weight;
} else if (@Frame == 4) {
    // Reset the custom attribute to 0 at frame 4
    @impregnated_weight = 0;
}

// Use the stored value from frame 3 if available, otherwise use @weight
if (@Frame > 3) {
    @weight = @impregnated_weight;
}

// Optionally, you can do additional operations on @weight here
// For example, you can multiply it by some factor:
// @weight *= 2;



 

if (@Frame == 3) {
    if (s@initialized != 1) {
        s@initialized = 1;
        f@storedWeight = @weight;
    }
} else if (@Frame == 4) {
    if (s@initialized == 1) {
        @weight = f@storedWeight;
    }
}



 

if (@Frame == 3 && !@changed) {
    @changed = 1; // Mark this point as changed on frame 3
    @prev_weight = @weight; // Store the weight at frame 3
} else if (@Frame != 3 && @Frame > 3 && @changed) {
    @weight = @prev_weight; // Restore the weight from frame 3 on subsequent frames
}

 

Link to comment
Share on other sites

46 minutes ago, Librarian said:
int specificFrame = 3; // Define the specific frame

if (@Frame == specificFrame) {
    @myStoredValue = @weight; // Store the value of @weight at frame 3
}

if (@Frame > specificFrame && @myStoredValue != 0) {
    @weight = @myStoredValue; // Use the stored value for subsequent frames if it's not 0
}

@anbt Just wondering if anything here its Correct  ?? is it working in your Case ?.. :rolleyes:

so, this seems to make it work, thanks! Not sure yet if it is bomb proof. Only works if I specify the frame number. Will have a look at the rest of your code
I wrote it like that for now.

 

if (@Frame == 3) {
    @prevF = @weight;
}

if (@Frame > 3 && @prevF != 0) {
    @weight = @prevF; 
}

f@prevF = @prevF;

if (@prevF==0) {
    i@active=0;
    } else if (@prevF!=0) {
        i@active=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...