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

Calling a function from onClick

Explorer ,
Aug 16, 2022 Aug 16, 2022

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
341
Translate
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

Try declaring res.

Put "var" before res.

Translate
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

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

Translate
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

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

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

Translate
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
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?

Translate
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