Skip to main content
Inspiring
January 9, 2018
Answered

Expression for source text

  • January 9, 2018
  • 1 reply
  • 2727 views

I have this line in an expression on one layer (say "LayerA"):

randNum=Math.round(random(0,4))+effect("Color Offset")("Slider");

Is there a way i can use 'randNum' from LayerA as the SourceText for a separate text layer (layerB)?

    This topic has been closed for replies.
    Correct answer Mylenium

    You have a completely wrong understanding how expressions in AE work. There is no such think as global variables and the return value is always the absolute value of the property stream, nothing more, regardless whether it's generated by keyframes, expressions or a combination of one on top of the other. If the code is part of a larger construct, then you need to post the code in its entirety. Otherwise nothing stops you from generating the random values on a separate expression control if it needs to be re-used by multiple other expressions. Again, you simply have things backwards.

    Mylenium

    1 reply

    Mylenium
    Brainiac
    January 9, 2018

    Simply pickwhip the expression to the source text.

    Mylenium

    reindeer4Author
    Inspiring
    January 9, 2018

    Hey Mylenium -

    I tried pickwhipping to the line defining randNumber, but that doesn't work.

    And my problem is randNumber is not the final output of LayerA - it's simply used in a larger chunk of code.

    I was hoping to link to some variables and show them on screen as text so I could try to debug the code and figure out where things are going wrong.  Wasn't sure if I needed to use Return to make the variable available to other layers, or make it a Global as opposed to Local variable, or do anything with numbers to text.  If any of those would work, i was hoping someone could show me the syntax to use in After Effects.  From what I've read online, I'm not sure that After Effects lets you directly access another layer's variable - so was just trying to get some clarification.

    Mylenium
    MyleniumCorrect answer
    Brainiac
    January 9, 2018

    You have a completely wrong understanding how expressions in AE work. There is no such think as global variables and the return value is always the absolute value of the property stream, nothing more, regardless whether it's generated by keyframes, expressions or a combination of one on top of the other. If the code is part of a larger construct, then you need to post the code in its entirety. Otherwise nothing stops you from generating the random values on a separate expression control if it needs to be re-used by multiple other expressions. Again, you simply have things backwards.

    Mylenium