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

Calling a function from onClick

Explorer ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

I have a scriptUI palette I'm working on. Making progress but now my button won't run the function. Is this correct?

 

            myPanel.grp.groupOne.groupTwo.createSnipesButton.onClick = function() {
                alert("trying to run the function");
                createSnipes();
                }

then my function should run when that button is clicked. I have this dialog stuff happening in a function and the createSnipes() function is outside this. Does something need to happen differently? Maybe it can't reach outside itself?

ByronNashINSP_0-1660688485284.png

I collapsed all the functions so you can see the top level structure. 

TOPICS
Scripting

Views

163

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
Participant ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

Try declaring res.

Put "var" before res.

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
Participant ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

Also, #target not required, i generally don't use as i run the script from File> script > run script.

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 ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

I tried that but it didn't work. Is it because this palette is nested in a function twice?

function myScript(thisObj){
    function myScript_buildUI(thisObj){

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 ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

I think I fixed it. I moved all those functions I had under the myScript() function. 

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 ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

LATEST

I cannot get my functions to call now. If I nest them in the function I'm in it works, but if I leave them all at a higher level they won't run. I can't keep nesting functions inside of other functions because many are reused throughout the script. I tried to write one of them to a separate file and use #include but it does not seem to work either. What am I doing wrong?

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