2351 posts Small, but tough
  • Has referred 500+ members
  • Has sold $125,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+9 more
EFEKT_Studio says

So guys, I don’t know if it’s even possible (felt should know this one).

Maybe it’s not possible as I said, but maybe it’s simple as banana.

So, we have a text layer. Exactly: text.sourceText

I’m crushing my head here with this expression I added to some other layer:

if(thisComp.layer(“Text layer”).text.sourceText=”a”) {100} else 0

What I’m trying to do is if I enter character “a” in text layer to get result 100 for example, otherwise 0

Possible?

5094 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Helps us moderate the forums
+11 more
felt_tips Volunteer moderator says

You’re using a single = sign. This is used to set the value on the left to the value on the right. I’d need to check what happens here, as I’m not sure you can set the parameter in that way. In any case, the if statement will probably return true if it is able to set the sourceText to “a” and false if it isn’t. You need to use the comparitive ==

Also, you have to be careful with expressions. After Effects allows you a shorthand that allows you to write thisComp.layer(“my layer”).position; and AE will be clever enough to work out that you mean thisComp.layer(“my layer”).transform.position.value; It works this out apparently by looking at the type of data expected. This doesn’t always work with a string, as a string can contain pretty much anything (converted to a string of course). Technically speaking, thisComp.layer(“Text Layer”).text.sourceText will return [Object Property]. It’s the value of that [Object Property] that you’re after and sometimes you need to be explicit about it. I think in your case here, it’s okay… in fact I’m not sure what stops After Effects from recognising the data-type. Maybe I’m confusing with scripting here.

One other thing to watch out for is that if you are mixing up calculated values and letters in a single string, you may sometimes need to use the toString() method to make sure everything’s string compatible.

For instance
var x = 23; var y = 12.1;
var a= x*y;
var returnText = “Result\nThe number I calculated is ” + a.toString();

You’ve also missed some curly braces off the second part of your if statement

Your expression should look like this…

if(thisComp.layer("Text Layer").text.sourceText.value == "a") {100;} else {0;}

You can also write the if statement like this.

var returnText = (thisComp.layer("Text Layer").text.sourceText.value == "a") ? 100 : 0;
2351 posts Small, but tough
  • Has referred 500+ members
  • Has sold $125,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+9 more
EFEKT_Studio says

YES FELT !! That’s it!! Thank you so much… I know I should use ==, but I thought it is for numerical value, and that = is for character value… Great, thnx!

5094 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Helps us moderate the forums
+11 more
felt_tips Volunteer moderator says

= sets a value, == compares two values.

To see what I mean about values and strings, try setting up a layer called “Other Layer” and making a Slider Control effect on it and set its value to 12.

Then make a text layer and paste this into the Source Text property:

"hello " + thisComp.layer("Other Layer").effect("Slider Control")(1).toString();

You will see “hello [Object Property]” as the result. If you try the same thing with the little addition of .value…..

"hello " + thisComp.layer("Other Layer").effect("Slider Control")(1).value.toString();

Then you will see “hello 12”;

You can also replace the (1) in the above statements with (“Slider”). In fact (“Slider”) is the AE default, but for effects that only have one property anyway, I find that using the index is a space saving option. It also has the advantage that an index can be opened in an alternative language version of AE, whereas the name will give an error.

2351 posts Small, but tough
  • Has referred 500+ members
  • Has sold $125,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+9 more
EFEKT_Studio says

This is cool, I’m trying to get more into scripting :)

5094 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Helps us moderate the forums
+11 more
felt_tips Volunteer moderator says

This is cool, I’m trying to get more into scripting :)

The above will work in expressions and scripting.

1615 posts I create things I wish existed
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Won a competition
  • Made it to the Authors' Hall of Fame
+8 more
cyzer says

Hello, just dont want to create a new thread. Can anyone tell me how to time-animate only one value.

I mean in example there is position – 640.360 ..

if I just alt click on it and write time*20 then both axis are changed over time. what if I need to time-animate only y axis?

how to do that

13 posts
  • Has sold $40,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Located in Australia
  • Has been part of the Envato Community for over 2 years
+5 more
EmperorVFX says

Hey Cyzer, you need to create a variable for your time animation.

If you want to affect y value only, you add the variable to the ‘y’ value in the position string.

Which looks like this:
var timeAnim = time * 20;
[value[0], value[1] + timeAnim];

I hope that made sense :)

by
by
by
by
by
by