Forums › Adobe After Effects Expressions › Changing variable value based on multiple conditions
Changing variable value based on multiple conditions
Kevin Snyder
May 7, 2020 at 6:48 amI’m trying to change the value of a variable based on four different conditions so that in each condition the value of the variable will be different. I’m trying the code below, but running into some errors. Is there a better way to tackle this?
if (myProp && !altKey)
{var myControl = myEffect + " " + myGroup + " " + "-" " " myLayerName}
else if (!myProp && altKey)
{var myControl = myEffect}
else if(!myProp && !altKey)
{var myControl = myEffect + " " + "-" " " myLayerName}
else if (myProp && altKey)
{var myControl = myEffect + " " + myGroup};Robert Müller
May 7, 2020 at 8:27 amHi, just so that I understand correctly: The four conditions HAVE to be based on the 2 different variables myProp and altKey and their different states? Can you share some more details why 1 variable wouldnt be enough?
Andrei Popa
May 7, 2020 at 11:14 amYou can’t have strings like that without + between them. Try this
if (myProp && !altKey) {
var myControl = myEffect + " " + myGroup + " " + "-" + " " + myLayerName;
} else if (!myProp && altKey) {
var myControl = myEffect;
} else if (!myProp && !altKey) {
var myControl = myEffect + " " + "-" + " " + myLayerName;
} else if (myProp && altKey) {
var myControl = myEffect + " " + myGroup;
}
Andrei
My Envato portfolio.Kevin Snyder
May 7, 2020 at 7:27 pmThank you for the feedback Andrei. I appreciate it!
Log in to reply.