Using nested CURRENT("Z") function calls in an onClick Behaviors ANIMATE function call

For testing/example purposes, I have a simple DC Cube dynamic component. My goals with the DC are to: 1) Place multiple copies of the DC at ANY Z position in the model’s global XYZ axes coordinates. 2) Be able to use the Interact tool to click on ANY component copy and have the component copy move up along the Z axis on the first click, and move back down along the Z axis the same amount on the second Interact click.

The DC functionality I’m trying to use for my simple DC Cube is:

My SU example file is:
DC Test H.skp (57.6 KB)

For reasons I do not understand, my DC behavior is working as expected for the first Interact tool click on any copy of the DC —specifically moving up along the Z axis from wherever the component copy is located. However, the SECOND Interact tool click on the component is NOT moving the component back down along the Z axis. Instead, it keeps moving the component up along the Z axis.

It appears that ALL the values used by the ANIMATE function (a list of values) are set upon the first Interact tool click on the DC vs each value being used by the ANIMATE function being evaluated on each successive Interact tool click on the DC.

What am I doing wrong, or just not understanding, regarding how I think my DC’s onClick behavior should be working? I had hoped/assumed the CURRENT(“Z”) function would be called, and return an updated value, upon each successive Interact tool click on my DC.

You want to go from the current and back, then set an attribute to change the direction of the added distance.
Two examples in the attached, one that keeps adding to the current, one with the added attribute to change direction

set a second attribute for direction.skp (26.1 KB)

Thanks pcmoor!! I’ve been fighting with this for a long time.

Based on your feedback, this is how my “DC Cube” component attributes are now defined to get my desired first click moves up, second click moves it back functionality:


The DC can now be copied anyplace and any number of times in the model space and each copy’s onClick behavior works as intended.

For my own clarification, I had to carefully reread the ANIMATE function’s documented behavior to fully grasp that it is changing the value of the attribute it is animating (“Z”) between the first (state1) and second (state2) state parameter values on the first Interact tool click and from state2 back to state1 on the second Interact tool click.

This is different than my previous assumption that it was setting the attribute to those values on each successive Interact tool click.

Of course, your suggestion to add the SET function call to the onClick behavior list of functions to execute on each Interact tool click is the real trick that gave me my desired move it, then move it back behavior.

To clarify, the problem in your original is that the value of the objects current state was not in the formula, you had one above and one below it; hence it returns the first value, which is fortunate rather than returning an error. (this return can be used to ones advantage in other situations)