Jump to: Board index » General » Fusion

Increment/Decrement a Control in Expression

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

purplemagic

  • Posts: 58
  • Joined: Tue Jan 05, 2021 9:23 pm
  • Real Name: Justin Lewis

Increment/Decrement a Control in Expression

PostWed Jun 09, 2021 3:06 am

How do you increment or decrement a control's value in expression?

For example, suppose you want to change a Transform's Size at random.

Code: Select all
Size + math.random(-0.1, 0.1)


However, the code above won't work since a control can't reference its current or previous values.

Any suggestions?
Offline
User avatar

Bryan Ray

  • Posts: 2478
  • Joined: Mon Nov 28, 2016 5:32 am
  • Location: Los Angeles, CA, USA

Re: Increment/Decrement a Control in Expression

PostWed Jun 09, 2021 3:45 am

You have to use a loop that integrates across the timeline. You can write more complex code in an expression by starting it with a colon (:) symbol, but you then have to explicitly use a return to set the end result. Each statement must end in a semi-colon (;) For instance:

Code: Select all
:var = 1; randomseed(0); i = 0; while i<time do i=i+1; var = var+random(-1,1)*0.1; end; return var


I believe random() will only spit out integers, thus the multiplier. I commonly add a UserControl to give a random seed so that the expression can be randomized but still be repeatable.
Bryan Ray
http://www.bryanray.name
http://www.sidefx.com
Offline

purplemagic

  • Posts: 58
  • Joined: Tue Jan 05, 2021 9:23 pm
  • Real Name: Justin Lewis

Re: Increment/Decrement a Control in Expression

PostThu Jun 10, 2021 12:50 am

Worked like a charm. Thanks, Bryan.

Return to Fusion

Who is online

Users browsing this forum: BMDR User 9201 and 36 guests