Can anyone explain why including a print command is making this work, but when I remove it, I get nothing?
Double check your indentation.The print call is an extra tab in. I'd need to see the rest of the code to understand what side effect that is causing.
Ah, I see. I did a quick test to tinker with it because I wasn't sure. Since the print function is nested one layer deeper than it should be, the function thinks that is all it supposed to execute on and the for loop below it is considered to be not part of the function.
This means it gets run automatically whether you click on anything or not.
See this simplified example, remove the test and you'll see the same results, remove a tab from the print line and it won't get run until the layer is clicked, as it should work.