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

Syntax Error when using Template String in script

Community Beginner ,
Jan 30, 2024 Jan 30, 2024

Copy link to clipboard

Copied

Hello,

I'm creating a little After Effects panel with a button that adds an expression to the selected property. I'm trying to use Template Strings (String Literals or Template Literals, whatever is named) for the expression because I want to make it multiline and also interpolate variables into that expression.

 

For some reason, whenever I launch the panel from the Window menu, it gives me a "Syntax Error" message on whatever line that has the backticks (`) for the template string.

 

I know that template string are usable in expressions but, do they work in scripts or not? I thought that scripts would use Javascript as well.

 

I'm currently using AE 24.1.0 Build 78 on MacOS Ventura 13.5

 

Thanks in advance

TOPICS
Expressions , Scripting

Views

143

Translate

Translate

Report

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
Adobe Employee ,
Jan 30, 2024 Jan 30, 2024

Copy link to clipboard

Copied

Hi @willsc123,

Template strings are not supported by scripting, though they are supported in expressions. Scripting and expressions use different versions of JavaScript; scripting uses ExtendScript, which is effectively ECMAScript3 with some Adobe-specific methods added, while expressions use modern JavaScript (at least ECMAScript 6).

 

You might be able to add the backticks to the expressions by using the character code at the time the expression is applied. That way it won't cause the scripting side to error.

 

Cheers,

- John, After Effects Engineering Team 

Votes

Translate

Translate

Report

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 Beginner ,
Jan 30, 2024 Jan 30, 2024

Copy link to clipboard

Copied

Oh, too bad to hear that! Are there any plans to upgrade the scripting engine to a more modern language?

 

I'll try what you suggest but I don't think it will work because I need the backticks on the script code, not on the expression. I wanted to use template string format for writing the expression string and interpolate variables from the script into the final expression, instead of writing the expression as an array and having to join all the lines.

 

I can workaround the problem with arrays, I just wanted a more concise and cleaner code.

 

Thanks for your help!

Votes

Translate

Translate

Report

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
Adobe Employee ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

You shouldn't need backticks in the script code to apply them in the expressions, only inside the expression strings themselves. Take a look inside this script for applying expressions for animating variable width typefaces: https://github.com/AdobeDocs/after-effects/blob/fa149f419a7df53953b4208a17c2f20ea6d4db9e/samples/Ins.... The linked function for building the expressions utilizes backticks and template strings, but is applied from ExtendScript.

 

We have investigated using a more modern scripting language for application scripting, similar to what Photoshop is using for extensions, but roadmap and planning aren't discussed publically for legal reasons.

 

I hope the script example is helpful,

- John, After Effects Engineering Team 

Votes

Translate

Translate

Report

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 Beginner ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

LATEST

Hi John,

 

Thanks for the example. However, I think I didn't explain myself correctly. I'll paste a snippet of code for what I'm trying to do:

 

var minVal = 0;
var maxVal = selectedProperties[0].value;
var dur = 1;

/* ----- WORKAROUND (This works for what I want to do) ----- */

var expArray = [
	'var d = ' + dur + ';',
	'var min_value = ' + minVal + ';',
	'var max_value = ' + maxVal + ';',
	'',
	'// quartic easing in/out - acceleration until halfway, then deceleration',
	'function easeInOutQuint(t, b, c, d) {',
	'	t /= d/2;',
	'	if (t < 1) return c/2*t*t*t*t + b;',
	'	t -= 2;',
	'	return -c/2 * (t*t*t*t - 2) + b;',
	'};',
	'',
	'if (time <= inPoint + d ) {',
	'	var n = easeInOutQuint(time - inPoint, min_value, max_value - min_value, d)',
	'}',
	'',
	'else if (time > inPoint + d && time < outPoint - d) {',
	'	var n = max_value',
	'}',
	'',
	'else if (time >= outPoint - d && time < outPoint) {',
	'	var n = easeInOutQuint(time - outPoint + d, max_value, min_value - max_value, d)',
	'}',
	'',
	'else {',
	'	var n = min_value',
	'}',
	'',
	'[n,n]',
	]
expArray.join("\n")

/* ----- PREFERRED WAY (I would like to do it this way because of the easier and cleaner code------ */

var expString = 
	`
	var d = ${dur};
	var min_value = ${minVal};
	var max_value = ${maxVal};
	
	// quartic easing in/out - acceleration until halfway, then deceleration'
	function easeInOutQuint(t, b, c, d) {
		t /= d/2;
		if (t < 1) return c/2*t*t*t*t + b;
		t -= 2;
		return -c/2 * (t*t*t*t - 2) + b;
	}
	
	if (time <= inPoint + d ) {
		var n = easeInOutQuint(time - inPoint, min_value, max_value - min_value, d)
	}
	
	else if (time > inPoint + d && time < outPoint - d) {
		var n = max_value
	}
	
	else if (time >= outPoint - d && time < outPoint) {
		var n = easeInOutQuint(time - outPoint + d, max_value, min_value - max_value, d)
	}
	
	else {
		var n = min_value
	}
	
	[n,n]
	`

 

 That doesn't work because of the backticks raising an error. I didn't want to use them inside the expression, as in the example, but in the script for creating that multiline string above.

 

I understand this may be not possible at the moment so I'll have to wait for an update on the scripting language. Hope it is soon!

 

Thanks again for all of your help.

 

Regards,

Guillermo

Votes

Translate

Translate

Report

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