Computer Science Canada Is it possible to make a button that when clicked the program exits, and how can it be done? |
Author: | skillspeed [ Wed Jan 18, 2012 5:01 pm ] | ||
Post subject: | Is it possible to make a button that when clicked the program exits, and how can it be done? | ||
What is it you are trying to achieve? <Replace all the <> with your answers/code and remove the <>> I have an isp and I am trying to make a button that when clicked exits the program, what the program is doesent matter I just need the program to exit when the button is clicked. What is the problem you are having? <Answer Here> I am not sure how you go about doing this, I dont know if there is a command that does this, etcDescribe what you have tried to solve this problem <Answer Here> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here> This is all I know about making buttons: var x, y, bnum, bud : int drawfillbox ( 100, 280, 200, 310, 4) drawfillbox ( 100, 240, 200, 270, 2) drawfillbox (100, 200, 200, 230, 1) if x >= 100 and x <= 200 and y >= 280 and y <= 310 then colour ( 4) put "You clicked the red box" elsif x >= 100 and x <= 200 and y >= 240 and y <= 270 then colour (2) put "You clicked the green box" elsif x >= 100 and x <= 200 and y >= 200 and y <= 230 then colour (1) put "You clicked the blue box" else colour (4) put "Tsk tsk. You did not click inside a box." end if
Please specify what version of Turing you are using <Answer Here> 4.1.1 |
Author: | Dreadnought [ Wed Jan 18, 2012 6:16 pm ] |
Post subject: | Re: Is it possible to make a button that when clicked the program exits, and how can it be done? |
I'm not sure what exactly you mean by exit, but I would suggest you read the documentation for Window.Close and return. They might help you accomplish what you want. If the behavior you wanted was that of Window.Close, remember that the default Turing window's id is "defWinId". |
Author: | Insectoid [ Wed Jan 18, 2012 6:36 pm ] |
Post subject: | RE:Is it possible to make a button that when clicked the program exits, and how can it be done? |
'exiting a program' really just means there's no more code to execute. So the question becomes, if the button is clicked, how do I skip the rest of the code? |
Author: | Zren [ Wed Jan 18, 2012 6:53 pm ] |
Post subject: | RE:Is it possible to make a button that when clicked the program exits, and how can it be done? |
I assume you've looked into Mouse.Where, but as you didn't put it in your code... You also need to be constantly checking, not just once. |
Author: | Velocity [ Wed Jan 18, 2012 9:04 pm ] |
Post subject: | RE:Is it possible to make a button that when clicked the program exits, and how can it be done? |
look up GUI.QUIT |
Author: | Raknarg [ Thu Jan 19, 2012 10:56 am ] |
Post subject: | RE:Is it possible to make a button that when clicked the program exits, and how can it be done? |
He's using Mouse.Where buttons, not GUI. |
Author: | tg851 [ Thu Jan 19, 2012 11:18 am ] |
Post subject: | RE:Is it possible to make a button that when clicked the program exits, and how can it be done? |
a way to just quit the program,with custom error quit text is "Error.Halt("message here")" very useful for various things |
Author: | Beastinonyou [ Thu Jan 19, 2012 1:17 pm ] | ||
Post subject: | Re: Is it possible to make a button that when clicked the program exits, and how can it be done? | ||
You could approach this by using a boolean, so when the user clicks that button, the boolean becomes true, and will exit the main loop. You could then close the window manually |
Author: | turinghelp101 [ Thu Jan 19, 2012 4:51 pm ] | ||
Post subject: | Re: Is it possible to make a button that when clicked the program exits, and how can it be done? | ||
Beastinonyou @ Thu Jan 19, 2012 1:17 pm wrote:
You could approach this by using a boolean, so when the user clicks that button, the boolean becomes true, and will exit the main loop. You could then close the window manually I think this is what the guy was asking: Instead of having to click manually to close the window, he wants a button that when clicked on closes the window |
Author: | turinghelp101 [ Thu Jan 19, 2012 4:57 pm ] |
Post subject: | Re: Is it possible to make a button that when clicked the program exits, and how can it be done? |
I found this in a turing reference, this should help you: import GUI const screenWidth : int := Config.Display (cdScreenWidth) const screenHeight : int := Config.Display (cdScreenHeight) const titleBarHeight : int := 32 const windowEdgeSize : int := 13 const windowWidth : int := 150 const windowHeight : int := 100 var windowID, windowNumber, closeButton, quitButton : int := 0 procedure CloseAndOpen if windowID not= 0 then GUI.CloseWindow (windowID) end if windowNumber += 1 var xPos : int := Rand.Int (0, screenWidth - windowWidth - windowEdgeSize) var yPos : int := Rand.Int (0, screenHeight - windowHeight - titleBarHeight) windowID := Window.Open ("title:Window #" + intstr (windowNumber) + ",graphics:" + intstr (windowWidth) + ";" + intstr (windowHeight) + ",position:" + intstr (xPos) + ";" + intstr (yPos)) closeButton := GUI.CreateButton (10, 60, 130, "Close And Open", CloseAndOpen) quitButton := GUI.CreateButton (10, 10, 130, "Quit", GUI.Quit) end CloseAndOpen CloseAndOpen loop exit when GUI.ProcessEvent end loop GUI.CloseWindow (windowID) |
Author: | Alex C. [ Thu Jan 19, 2012 5:14 pm ] |
Post subject: | RE:Is it possible to make a button that when clicked the program exits, and how can it be done? |
GAAAAAAHHHHHHH! use code tags for the love of god!!! > ![]() |
Author: | chipanpriest [ Fri Jan 20, 2012 12:30 pm ] | ||||
Post subject: | Re: Is it possible to make a button that when clicked the program exits, and how can it be done? | ||||
Beastinonyou @ Thu Jan 19, 2012 1:17 pm wrote:
You don't need a boolean value. Just tell the loop to exit. For example:
|