StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General Discussion
 General Discussion
 Stop script execution
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Pietro

2 Posts

Posted - 03/05/2016 :  16:16:30  Show Profile  Reply with Quote
Hey guys,

I'm not the master in programming. But I can do some relatively complex keystrokes stuff (using loops, tables and input boxes) to automate boring tasks, that I have to do in my music software. Like rendering stems.

Is there a way to instantly stop the script from further execution? I do a lot of hit and miss stuff (delays is one of those variables, I have to check on a living organism) and I'd like to stop the script from progressing as soon as I see something going wrong. The only way I see now is just exiting S+.

Cheers,
- Piotr

Rob

USA
2514 Posts

Posted - 03/05/2016 :  16:26:22  Show Profile  Visit Rob's Homepage  Reply with Quote
That's actually an interesting one. Since the script will continue executing in one thread, you'll need to set a flag somewhere outside of, but accessible by, the running script's thread. There are many ways to handle this, but a simple one I just tested is this:
acMessageBox("starting")
acDelay(10000)
if acGetNumber() == 1 then
	acSetNumber(0)
	return
end
acMessageBox("continue script")
Then, in a separate action (or S+ hotkey maybe easier), put this:
acSetNumber(1)
So basically, once you call the acSetNumber to store the number 1 inside S+, you can check that number in your main script, if it's 1, set it back to 0 and exit the script ("return").
Go to Top of Page

Pietro

2 Posts

Posted - 03/06/2016 :  07:02:22  Show Profile  Reply with Quote
Thanks. This could actually work. Only thing is, I would need to place the "control point" in a couple of places within the loop, otherwise a lot could go wrong in the meantime, and not everything is undoable.

I was also looking for a way to kill StrokesPlus and restart it with a (non S+) key macro. Not sure how to kill the process using only keyboard?

If I were to have a feature request, that single key/gesture to immediatelly stop scripts from fuher execution would be on my priority list.

Thanks! This is generally an incredibly useful piece of software.
- Piotr
Go to Top of Page

Rob

USA
2514 Posts

Posted - 03/06/2016 :  10:39:04  Show Profile  Visit Rob's Homepage  Reply with Quote
Lua scripts (the scripting engine used by S+) are single-threaded and there's really no safe way to stop the script from the application (S+). Meaning, you would have to build that into your script itself. I can certainly force-kill the whole Lua engine, but not without causing S+ to crash as well; or at a minimum have to create an exception handler to catch the crash, but then it leaves things in a not so great state and isn't worth the risk. The other alternative is to use debug hooks, but that would slow down all of S+ and also not be worth it. Look at the second response on this post, it explains it quite well: http://stackoverflow.com/questions/9135200/break-a-lua-script-in-c-from-another-thread

You may also read up on Lua coroutines/yielding: http://www.tutorialspoint.com/lua/lua_coroutines.htm

Coroutines let you pause and resume execution paths. It's certainly a more advanced topic and I'm not even sure if it would be useful based on what you're doing, since I don't know exactly what the purpose of your script is.

I modified one of the examples on that page to use acMessageBox instead of print, since print wouldn't show you anything in S+ (you can copy/paste the whole block of code below into a single action).
function getNumber()
   local function getNumberHelper()
      co = coroutine.create(function ()
      coroutine.yield(1)
      coroutine.yield(2)
      coroutine.yield(3)
      coroutine.yield(4)
      coroutine.yield(5)
      end)
      return co
   end
	
   if(numberHelper) then
      status, number = coroutine.resume(numberHelper);
		
      if coroutine.status(numberHelper) == "dead" then
         numberHelper = getNumberHelper()
         status, number = coroutine.resume(numberHelper);
      end
		
      return number
   else
      numberHelper = getNumberHelper()
      status, number = coroutine.resume(numberHelper);
      return number
   end
	
end

for index = 1, 10 do
   acMessageBox("index: "..index.." - getNumber():"..getNumber())
end
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000