Computer Science Canada Executing a command when the program is interrupted |
Author: | supaphreek [ Tue May 18, 2010 4:39 pm ] |
Post subject: | Executing a command when the program is interrupted |
What is it you are trying to achieve? I want it the turing program to run a command if the user press' stop or the red x at any time What is the problem you are having? Cant figure it out Describe what you have tried to solve this problem Looping it on and off (but its not what i want ![]() Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) None Please specify what version of Turing you are using 4.1.1 |
Author: | Monduman11 [ Tue May 18, 2010 4:44 pm ] |
Post subject: | Re: Executing a command when the program is interrupted |
umm i dont think you can do that in turing but i might be mistaken... what command are you trying to execute while you program is being interupted? Edit: so wait are you trying to add a pause button to your program? im confused lol |
Author: | andrew. [ Tue May 18, 2010 5:04 pm ] |
Post subject: | RE:Executing a command when the program is interrupted |
Unfortunately, you can't do exactly that in Turing. You can however, check the x and y coordinates of the mouse and when they hover over the red button, it can do something. You cannot do anything if the user closes the program or presses stop or pause though. Just another limitation of Turing. |
Author: | DemonWasp [ Tue May 18, 2010 5:04 pm ] |
Post subject: | RE:Executing a command when the program is interrupted |
Running commands when the window is closed or the stop button at the top is pressed is not possible in Turing. There are simply no commands or objects that you can access to make that happen. This is contrary to many other programming languages / user interface toolkits, wherein clicking the close button (or alt+f4) will fire an event describing the action and the program can continue running. At best, you can remove the button bar at the top with View.Set ( "nobuttonbar" ); however, that doesn't hide the close button and it certainly doesn't prevent Alt+F4. |
Author: | supaphreek [ Tue May 18, 2010 5:36 pm ] |
Post subject: | RE:Executing a command when the program is interrupted |
Thanks to all of you! what im going to do is use nobuttonbar and make an x/y coordinate for when it goes over the red x so if thats pressed, it should do the command before exiting i hope and for those wondering, im trying to get it to run an exe file using sys.exec ![]() |
Author: | Tony [ Tue May 18, 2010 5:42 pm ] |
Post subject: | RE:Executing a command when the program is interrupted |
Let me guess, you are trying to get the executable to lunch another instance of itself, so that a user can't quit? |
Author: | supaphreek [ Tue May 18, 2010 5:53 pm ] | ||
Post subject: | RE:Executing a command when the program is interrupted | ||
Nope, what im actually trying to do is ... well, remember how i wanted to hide the mouse? i found a program that can do that, but its run as a .exe ![]() anyways, this is what ive gotten so far
The problem is, somethings wrong, because it wont exit the loop :S i even tried it with if button = 0 (and i even tried taking out the if button statement) and it still wouldnt exit the loop and open nomousy.exe :S I dont know what the problem is. I tried using loop and just set a delay and a counter to exit at and that seemed to work, so it seems the code inside the loop is preventing it from exiting. Anyone who can help, it would be appreciated! |
Author: | chrisbrown [ Tue May 18, 2010 6:10 pm ] |
Post subject: | Re: RE:Executing a command when the program is interrupted |
supaphreek @ Tue May 18, 2010 5:53 pm wrote: i even tried it with if button = 0 (and i even tried taking out the if button statement)
This is the wrong way to debug. supaphreek @ Tue May 18, 2010 5:53 pm wrote: it seems the code inside the loop is preventing it from exiting.
Am I correct in assuming you're trying to intercept the clicking of the close button? If so, it doesn't quite work that way. Windows will competely halt any execution inside that window and destroy it, so your program never actually reaches a button=1 state. The only solution (short of using another language) is to find another way for your user to gracefully exit. |
Author: | Tony [ Tue May 18, 2010 6:10 pm ] |
Post subject: | RE:Executing a command when the program is interrupted |
The problem is that if the user exists somehow else (Alt+F4 interrupts, program crash, kill process, etc.) then you still have the same problem (exit without restore). A typical approach to such problems is that there are two programs that are running at the same time -- your game + monitor program. The game starts up the monitor with Sys.Exec, the monitor turns off the mouse cursor and loops to make sure that the game is still running. Could be done with sockets, or writing heart-beats to a shared file. When the monitor detects that the game is no longer running, it restores the mouse cursor and exits itself. (Since you are going to need to have your programs compiled, you might want to use Turing 4.1 instead of 4.1.1) |
Author: | chrisbrown [ Tue May 18, 2010 6:15 pm ] |
Post subject: | RE:Executing a command when the program is interrupted |
Please ignore my previous post. I need to learn to read the entire thread before posting. I'm going to go back to lurking now. |
Author: | supaphreek [ Tue May 18, 2010 6:27 pm ] |
Post subject: | RE:Executing a command when the program is interrupted |
LOL, have fun chris ![]() Thanks tony, il definetly try that and i do have turing 4.1.1 ![]() |
Author: | Tony [ Tue May 18, 2010 7:39 pm ] |
Post subject: | Re: RE:Executing a command when the program is interrupted |
Tony @ Tue May 18, 2010 6:10 pm wrote: use Turing 4.1 instead of 4.1.1) |
Author: | supaphreek [ Tue May 18, 2010 9:04 pm ] |
Post subject: | RE:Executing a command when the program is interrupted |
OH, yea ![]() ![]() ANyways, could you please elaborate on how i would make a second program watch over the first one? what commands would i need to use and such? |
Author: | Tony [ Tue May 18, 2010 9:19 pm ] |
Post subject: | Re: RE:Executing a command when the program is interrupted |
Tony @ Tue May 18, 2010 6:10 pm wrote: Could be done with sockets, or writing heart-beats to a shared file.
>> Net |