Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to make a quit button.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
atal




PostPosted: Sat Sep 24, 2011 3:25 pm   Post subject: How to make a quit button.

Hi guys i have a question. What codding do i need to use to make a quit button. I have been searching around and did not find one that would work, i tried playing around with chars (INPUT_KEY_DOWN) and stuff like that with no success. Srry if this question has already been answered but i could not find it thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sat Sep 24, 2011 4:15 pm   Post subject: RE:How to make a quit button.

You'll need a boolean variable to record if the quit button has been pressed. At the bottom of your loop, check if your variable is true (meaning 'quit' has been pressed) and if so, exit the main loop. There are a number of tutorials available on creating buttons, so I won't explain that.

the basic premise is,

code:

bool quit_clicked := false
loop
    %main program
    if quit_clicked = true then
        exit;
    end if
end loop


Alternatively, you can use the 'quit' keyword which terminates the program, but it tells Windows that the program failed/crashed/whatever instead of terminating gracefully.
atal




PostPosted: Sat Sep 24, 2011 4:29 pm   Post subject: Re: RE:How to make a quit button.

Insectoid @ Sat Sep 24, 2011 4:15 pm wrote:
You'll need a boolean variable to record if the quit button has been pressed. At the bottom of your loop, check if your variable is true (meaning 'quit' has been pressed) and if so, exit the main loop. There are a number of tutorials available on creating buttons, so I won't explain that.

the basic premise is,

code:

bool quit_clicked := false
loop
    %main program
    if quit_clicked = true then
        exit;
    end if
end loop


Alternatively, you can use the 'quit' keyword which terminates the program, but it tells Windows that the program failed/crashed/whatever instead of terminating gracefully.


im sorry (im pretty new at this) but i don't understand what you mean. And i dont want to create a compicated button (yet) i just want it to be like when the use presses a button such as Q the program will terminate
Tony




PostPosted: Sat Sep 24, 2011 5:42 pm   Post subject: RE:How to make a quit button.

There is essentially just one way to terminate a program -- have to execution flow (current line being run) get to the very end of the program.

quit gets there really fast by throwing an exception (TIL that Turing has exceptions; @Insectoid documentation suggests that you could set the exit code to be that of a "success").

Another alternative is to handle loop terminations yourself through a series of exit conditions.

It really depends on the control flow of your program.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
atal




PostPosted: Sun Sep 25, 2011 11:38 am   Post subject: Re: RE:How to make a quit button.

Ok so i found this in the tutorial section.

code:
loop
var chars : array char of boolean

        Input.KeyDown (chars)
    %% This tells the program what your key var is.
    if chars ('q') then
        exit
    end if
end loop


When i add this to my program there is a problem. The problem is that the program uses the user to input a number and what i did is wrote press q to quit. so when i press q it just shows up in were the number should be entered. if i hit enter it syas invalid integer entered.
Tony




PostPosted: Sun Sep 25, 2011 1:02 pm   Post subject: RE:How to make a quit button.

we have tutorials on loops linked to from The Turing Walkthrough
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: