Watching for user input while in a loop

I’ve got a repeat loop going on that is performing several actions on text in an ASStudio app.

What I want to be able to do is to click a button, or press a key, and have the repeat loop stop its processing. I also want to be able to change the value of a slider while that loop is repeating.

Right now, it seems that the app concentrates solely on performing the loop, and won’t take any input from me at all during that time.

I know I can press CMD-. , but that’s a pretty poor way to interact with the app activity for an end-user of the built application.

Any suggestion would be greatly appreciated.

Thanks,

Laz

While in a repeat loop, an app will still respond to other events such as clicking a button. With that in mind, create a button called “cancel_loop” (or whatever you want) and then use the code below:

Jon


[This script was automatically tagged for color coded syntax by Script to Markup Code]

Thanks, once again, Jon. I look forward to giving you a registered-forever copy of this application if I ever get to the point where I can release it!

I can’t, however, get this method to work for the loop stuff.

When I press the “action” button, it starts off a loop that is in a subroutine, and the “action” button remains hilighted (as if it is engaged) the whole time the subroutine is running.

I have another button that sets a variable called ‘stopSign’ that is checked in both repeat loops of the subroutine.

stopSign, however, appears not to get set until I stop the subroutine with a CMD-. (which kind of defeats the whole purpose). :?

Any ideas?

Hmm, I’m getting the same results you are in a new project but I have several apps that work correctly using variations on the code I posted above. Let me do some more testing…

Jon

Thanks, Jon. I look forward to any further ideas you might have on this, because it really has me stumped!

Can you post something with a similar setup that you have working with this schema? I can help by going through and looking for differences that may be making the…um…difference.

:?

Laz

A variation on the code I posted above is used in my AS Studio app Name those Files! You can see it in action when you do anything that brings up the progress bar. In the progress panel, there is a stop button that will cancel the repeat loop.

Jon

I’m not quite sure why this wasn’t working for me before but it’s working fine now. I’ve created a little app that does nothing but demonstrate using a button to cancel out of a loop. The app (with source code) is available to download from:

[url=http://homepage.mac.com/jonn8/as/dist/Stop_Loop.hqx]http://homepage.mac.com/jonn8/as/dist/Stop_Loop.hqx[/url]

Let me know if you have any problems with it.

Jon

Thanks for the suggestions/examples, again, Jon. However, I still can’t get the functionality of my app working.

Perhaps it has to do with being able to set the ‘threaded’ of the progress indicator that allows you to escape the process…? I don’t know.

I have put together an extremely simple example project that shows the problem I’m trying to address.
http://http://www.miscmeta.com/hold/Stopper.sit

In this app there is a text field and two buttons. When the ‘Start’ button is clicked, the text field is updated every half second with progressively higher numbers.

I need some way to stop such a process (a key press, a button press…etc, etc). The “Stop” button tries to do this by setting a flag (stopSign), which is checked each time the counter loop is run.

As you can see in the built app, however, the “Start” button (and its related process) keeps control of everything, and only allows the “Stop” button event to be processed if you press CMD-. to quit the ongoing counting.

Any suggestions (button-wise, keyboard-wise (not CMD-. !) would be greatly appreciated.