2259 posts Small, but tough
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a File in an Envato Bundle
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a Free File of the Month
  • Bosnia and Herzegovina
  • Referred between 500 and 999 users
+4 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?

4793 posts
  • Community Superstar
  • Elite Author
  • Community Moderator
  • Sold between 100 000 and 250 000 dollars
  • Author had a File in an Envato Bundle
  • Beta Tester
  • Has been a member for 4-5 years
+6 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;
2259 posts Small, but tough
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a File in an Envato Bundle
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a Free File of the Month
  • Bosnia and Herzegovina
  • Referred between 500 and 999 users
+4 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!

4793 posts
  • Community Superstar
  • Elite Author
  • Community Moderator
  • Sold between 100 000 and 250 000 dollars
  • Author had a File in an Envato Bundle
  • Beta Tester
  • Has been a member for 4-5 years
+6 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.

2259 posts Small, but tough
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a File in an Envato Bundle
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a Free File of the Month
  • Bosnia and Herzegovina
  • Referred between 500 and 999 users
+4 more
EFEKT_Studio says

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

4793 posts
  • Community Superstar
  • Elite Author
  • Community Moderator
  • Sold between 100 000 and 250 000 dollars
  • Author had a File in an Envato Bundle
  • Beta Tester
  • Has been a member for 4-5 years
+6 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.

1512 posts I create things I wish existed
  • Elite Author
  • Won a Competition
  • Sold between 50 000 and 100 000 dollars
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
+3 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

12 posts
  • Sold between 10 000 and 50 000 dollars
  • Referred between 1 and 9 users
  • Bought between 50 and 99 items
  • Attended a Community Meetup
  • Author had a File in an Envato Bundle
  • Exclusive Author
  • Has been a member for 1-2 years
  • Australia
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