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

45

Likes

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

Copy link to clipboard

Copied

Try declaring res.

Put "var" before res.

Likes

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 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.

Likes

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){

Likes

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. 

Likes

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?

Likes

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