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

Math.random() suddenly not working

Explorer ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

I have imported into a current project an old project that had a fair bit of code, including quite a few Math.random() functions. This project worked fine at the time.

 

After Effects is reporting all the uses of Math.Random() as scripting errors: "Error: Math.random is undefined"

If I delete and re-type in the expression again exactly as it was, the error changes to: "Error: Math.random is not a function"

It seems like the Math scripting module(?) is not loading properly - but functions like "Math.floor()" work fine.

It is not complicated scripting. An example is (on a slider expression control):

1+Math.floor(Math.random(2));

 

Can anyone help?

TOPICS
Expressions , Scripting

Views

902

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

correct answers 1 Correct answer

Adobe Employee , Sep 06, 2023 Sep 06, 2023

Thanks for that sending over, @steveignite ! It appears the project is set to use the JavaScript engine (File > Project Settings > Expressions > Expressions Engine) but it's possible that you are importing it into a project that is using the Legacy ExtendScript engine. The Math.random() function didn't exist in the Legacy ExtendScript engine and shows the errors you are seeing.

 

Would you try checking the Expressions Engine in the project you are importing into and make sure it is set to JavaSc

...

Votes

Translate

Translate

correct answers 1 Pinned Reply

Adobe Employee , Sep 06, 2023 Sep 06, 2023

Hi @steveignite,

Thank you for reporting this issue. Would you be able to share the project with us? Also, which expression engine does the project use—JavaScript or Legacy ExtendScript?

 

Thanks for reporting this issue and for any further information you can provide,

- John, After Effects Engineering Team  

Votes

Translate

Translate
Explorer ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Just to add, if I open the old project, rather than importing it, it still works fine. It may be something to do with the project being converted from an older version of AE?

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
Explorer ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Another addition: I can open the old project, save it in the latest AE format, and it all works fine. But if I import that new AE project file into another new project, the problem persists.

 

So it seems to me to be a bug in the 'import project' feature.

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 ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Hi @steveignite,

Thank you for reporting this issue. Would you be able to share the project with us? Also, which expression engine does the project use—JavaScript or Legacy ExtendScript?

 

Thanks for reporting this issue and for any further information you can provide,

- 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
Explorer ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Hi John,

Thanks! Have sent you the project file.

AFAIK it just uses plain old javascript.

I figured a workaround of just saving the old project file and importing
my new project file containing the work I'd already done on the new
project instead. Hope you manage to figure out what's going on, though.

Ta!

Steve

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 ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Thanks for that sending over, @steveignite ! It appears the project is set to use the JavaScript engine (File > Project Settings > Expressions > Expressions Engine) but it's possible that you are importing it into a project that is using the Legacy ExtendScript engine. The Math.random() function didn't exist in the Legacy ExtendScript engine and shows the errors you are seeing.

 

Would you try checking the Expressions Engine in the project you are importing into and make sure it is set to JavaScript?

 

Alternatively, you can try using the random() function, instead of Math.random(), since that exists in both expression engines.

 

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 Expert ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

That's interesting. I've always thought that the expression language didn't include Math.random(), and that is the case if you use the Legacy Extendscript engine, but appently it was implemented with the new JavaScript engine. Maybe the project you're importing into is using the Legacy engine?

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 ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

@Dan Ebberts Yes, Math.random() came along with the new JS engine: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random. We did ensure it works with seedRandom() as well.

 

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
Explorer ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Thanks John, yes that's it - it was set to Legacy ExtendScript.

 

I'm not sure how it reverted to the legacy engine for the new project - I've only ever used Javascript for years - it's not a setting I've ever changed - but appreciate you figuring it out!

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 ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Glad to hear that solved the issue. As far as the legacy engine goes, that preference is "sticky", so if you opened an older project (pre-16.1) then any new project would default to that "last used" engine. We are considering a suggestion to have all projects default to the JavaScript engine to avoid situations like the one you encountered: https://community.adobe.com/t5/after-effects-ideas/expression-engine-should-always-default-to-javasc.... Please vote if you'd like to see this as well.

 

Thanks again,

- 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
Explorer ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

LATEST

Great, upvoted!

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