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

re: "Undefined" Value and Unable to Cancel in Script Prompt

New Here ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

Every time I run my script, there is an "undefined" value in the text field by default. Also, clicking cancel does not actually terminate the script; it moves on to the next part of the code (below).

script_prompt_01.jpg

script_prompt_02.jpg

var copies = parseFloat(prompt("Please enter number of copies (1 - 99): "));

while (copies < 1 || copies > 99 || isNaN(copies) ) {


copies = parseFloat(prompt("Please enter a numerical number between 1 and 99: "));


}

Any feedback why this behavior is happening? I've just recently been digging into AE scripting and am probably overlooking something obvious about the cancel function.

Thanks.

TOPICS
Scripting

Views

658

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

Engaged , Mar 07, 2018 Mar 07, 2018

From the javascript tools guide:

prompt()

Window.prompt (message, preset[, title ]);
message The string for the displayed message.
preset The initial value to be displayed in the text edit field.

Looks like you're missing the preset parameter from the prompt function call. Hence the [undefined] message in the prompt.


As for the script not terminating: are you running it from the extendscript toolkit? If not it won't debug and tends to fail silently and sometimes in unexpected ways. When I ran your cod

...

Votes

Translate

Translate
Engaged ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

From the javascript tools guide:

prompt()

Window.prompt (message, preset[, title ]);
message The string for the displayed message.
preset The initial value to be displayed in the text edit field.

Looks like you're missing the preset parameter from the prompt function call. Hence the [undefined] message in the prompt.


As for the script not terminating: are you running it from the extendscript toolkit? If not it won't debug and tends to fail silently and sometimes in unexpected ways. When I ran your code from ESTK it reported:

Error: Too many closing braces

That spurious error went away when I used

var copies = parseFloat(prompt("Please enter number of copies (1 - 99): ", 1));

So the runtime error has something to do with the missing parameter.

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
New Here ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

Thanks. I added the preset parameter below and it resolved the issue.

var copies = parseFloat(prompt("Please enter number of copies (1 - 99): ", ""));


However, clicking on 'Cancel' or 'X' still does not work and I am running from ESTK. The same happens when running the script from AE.

EDIT: ESTK version 4.0.0.1, After Effects CC 2017.2

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
Advocate ,
Mar 08, 2018 Mar 08, 2018

Copy link to clipboard

Copied

Break your script o logic parts so you can see where it brakes.

var copies = prompt("Please enter number of copies (1 - 99): ", "");

var value = parseValue(copies);

if (value === null) return;

while (value < 1 || value > 99 || isNaN(value) ) {

    copies = prompt("Please enter a numerical number between 1 and 99: ", "");

    value = parseValue(copies);

    if (value === null) return;

}

// other magic

alert("I got value " + value + "!");

function parseValue(copies) {

    // user canceled

    if (!copies) return null;

    // else user clicked OK;

    return parseFloat(copies);

}

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
New Here ,
Mar 08, 2018 Mar 08, 2018

Copy link to clipboard

Copied

LATEST

I see. One check to see if there is any value at all and one to test against the conditional statements. Thanks for the breakdown!

EDIT: This is also a "correct answer" to my original question.

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