[Closed] Retain original value while using condition expression
Still a newbie to maxscript…something troubled me a lot about retaining original value while using condition expression under script controller.
for example, A is assign with a float script controller.
And the contents are
if $sth == true then
B
else
A
But because of self dependency problem. We can’t assign it back to itself in order to retain the value after testing the condition. Even we remove the else part, undefined is return which is undesireable.
So normally how do you guys tackle this kind of problem? :S
As you have figured out, you cannot return the current value, but you have to return some value. Normally, when you assign a new Script controller, the current value is entered automatically as the return value. You should decide what the default value should be, and enter it in the else expression.
The way to keep this interactive is to use a List Controller as the master controller, and have an interactive Float Controller in the first track, with the Float Script controller in the second track, and the return value of 0 in the else expression. This means that the user can interactively adjust the value of the first controller, and as long as the condition is not met, the second controller will add 0 to the result, thus not affecting the final result. When the condition is met though, the result of the second (scripted) controller will be added to the existing value of the first (interactive, non-scripted) controller and change the final result of the List controller.
For example, if you want to adjust the Box Height value interactively AND with a script at the same time, you would
*Assign the Float List controller to the Height track
*Assign a Bezier Float to the Available track
*Assign a Float Script to the Available track (the first sub-track will remain the interactive one)
*Enter your script, for example
if $Box01.width > 100 then
$Box01.width
else
0
*Close the script.
Now if you go to the Modify panel and change the height with the mouse, the Box will react as usual because the new value will be stored in the first sub-track of the List controller, and the script will return 0 as long as the Width is below 100.
If you change the Box Width to a value above 100, then the condition of the script will be met and the height will suddenly jump to the Width value plus the value stored in the first, interactive track of the List controller!
Hope this help.
Cheers,
Bobo
well…what can i say…that’s has totally solved my problem…
Thanks a lot man. :bowdown:
why i never thought of that… :banghead: