Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Expression help - Error: cannot assign value

Contributor ,
Jul 09, 2021 Jul 09, 2021

Hi, I have a simple 2-item array (an x/y point position) and I want to change the value of the first item, but I'm getting an "Error: cannot assign value" on the line that attempts to change that value. Can anyone tell me what's going wrong? Here's my code:


xyPos = effect("Down Position")("Point");
if (thisComp.layer("Control").effect("Center Letter")("Checkbox") > 0){
xyPos[0] = xyPos[0]+88;
}
xyPos

 

Thanks!

TOPICS
Error or problem , Expressions
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 09, 2021 Jul 09, 2021

I think it will work if you change your first line to this:

xyPos = effect("Down Position")("Point").value;
Translate
Contributor ,
Jul 09, 2021 Jul 09, 2021

Note: I've tried the following command instead:

xyPos[0] = 88

 

...and it still gives the same error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 09, 2021 Jul 09, 2021

Booleans are explicit, so you can do a proper true/ false check and of course all the rest like not returning a full array to AE or providing a fallback when the condition isn't met. This should work:

 

Ref = effect("Down Position")("Point");
Switch=thisComp.layer("Control").effect("Center Letter")("Checkbox");

if (xySwitch != 0){
xPos = Ref[0]+88;
}
else{
xPos=Ref[0]:
}

[xPos,Ref[1]]

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2021 Jul 09, 2021

I think it will work if you change your first line to this:

xyPos = effect("Down Position")("Point").value;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 14, 2021 Jul 14, 2021

This worked perfectly. Can you explain to me why? Why is the ".value" needed?

 

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2021 Jul 14, 2021
LATEST

effect("Down Position")("Point") is an object representing the Point Control. Sometimes you can get away with referencing an object like that and the expression engine will figure out that you really wanted to use the value of that object, but not always. Sometimes you have to tell it explicitly with .value. So you can either just always stick .value in there when referencing expression controls, or do it when that error pops up.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines