I can't click my button.
Author |
Message |
doubleN
|
Posted: Sat Jan 01, 2011 10:27 pm Post subject: I can't click my button. |
|
|
What is it you are trying to achieve?
This is an assignment my teacher gave me and my classmates are too busy celebrating new years to help me. It's just a guessing game program
Also, I am in grade 9 computer science.
What is the problem you are having?
I have to add a button leading to the main menu of my program the display procedure. The button shows up, but I can't click on it. Any suggestions?
I also need to exit the program or reset the limit when the user has 3 tries, but don't worry about that for now
Anyway, I know there are some simpler ways to do some things, but I left my better code in class, and built upon the old stuff
Describe what you have tried to solve this problem
various loops and exit when statements, and I am clueless as to what I am to do
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
import GUI
var guess : int % The user's guess
var limit : int := 0 %Counter for how many tries the user has been taken
var num : int
var choice : string
var mainWin := Window.Open ("position:100;100,graphics:680;400")
%Program Title
proc title
cls
locate (1, 33)
put "Guessing Game"
put ""
end title
proc pauseProgram
var reply : string (1)
put ""
put "Press any key to continue...." ..
getch (reply )
end pauseProgram
proc randNum
randint (num, 25, 75)
limit := 0
end randNum
proc errorWindow
if guess < 25 or guess > 75 then
var errWin := Window.Open ("position:200;300,graphics:300;300")
put "That is not a number between 25 and 75."
put ""
put "Press any key to continue.."
loop
exit when hasch
end loop
Window.Close (errWin )
end if
end errorWindow
%User input
proc goodbye
title
locate (8, 4)
put "You've either given up or run out of tries. The number was ", num, ". How easy."
locate (10, 20)
put "This program was created by a pretty cool guy."
locate (11, 25)
put "For more information call Ghostbusters"% Because I don't like telemarketers
delay (2000)
Window.Close (mainWin )
end goodbye
proc userInput
title
locate (5, 1)
%Asking for and getting the user's guess
put "Enter a number between 25 and 75: " ..
get guess
%Opens a window which tells the user to enter another number if number is out of bounds
if guess < 25 or guess > 75 then
errorWindow
userInput
end if
GUI.Quit
end userInput
%New Game proc to reset then send to userInput
proc newGame
randNum
userInput
end newGame
%Main menu sending users to different procedures
proc mainMenu
title
%declaring the buttons
var playButton : int := GUI.CreateButtonFull (200, 200, 0, "New Game", newGame, 0, '^P', false)
var againButton := GUI.CreateButtonFull (200, 150, 0, "Continue", userInput, 0, '^A', false)
var quitButton := GUI.CreateButtonFull (200, 100, 0, "Quit", GUI.Quit, 0, KEY_ESC, false)
%Showing them %%% not sure if needed
GUI.Show (playButton )
GUI.Show (againButton )
GUI.Show (quitButton )
end mainMenu
%Button does not work
proc display
title
%to repeat the program until the user inputs a number in the range
if guess > num then %To detect when the user's guess is too high.
put "Come down!"
limit + = 1
elsif guess < num then
put "Way down there?" %For when the guess is too low.
limit + = 1
else
put "Good job!" %For telling the user when he's right
end if
%Creates a menubutton
var menuButton := GUI.CreateButtonFull (0, 100, 0, "Main Menu", mainMenu, 0, '^M', true)
GUI.Show (menuButton )
end display
%Main Program
proc introduction
randNum
title
var menuButton := GUI.CreateButtonFull (0, 100, 0, "Main Menu", mainMenu, 0, '^M', true)
GUI.Show (menuButton )
locate (3, 1)
put "This program will generate a random number."
put "Guess a number between 25 and 75."
end introduction
%Main Program
introduction
loop
exit when GUI.ProcessEvent
end loop
display
%I'm pretty sure that the problem is right here, the loop below is a last ditch effort
loop
exit when limit = 3
end loop
goodbye
|
Please specify what version of Turing you are using
4.1.1 or something
(please god don't let it be some obvious mistake) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Sat Jan 01, 2011 10:58 pm Post subject: RE:I can\'t click my button. |
|
|
Quote:
%I'm pretty sure that the problem is right here
Yup, you have an infinite loop right above. It should never get into "display" until you "Quit" GUI and disable all the buttons. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
doubleN
|
Posted: Sun Jan 02, 2011 1:38 pm Post subject: Re: I can't click my button. |
|
|
Ah, but GUI.Quit is located in "userInput". The thing is , the main menu will send the user into "userInput", and then after the user has entered their guess, the loop exits, going into display. Also, by disabling the buttons, do you mean GUI.Dispose? Will that make the menu button in "display" work, if I disable all my other buttons? |
|
|
|
|
|
Tony
|
|
|
|
|
doubleN
|
Posted: Sun Jan 02, 2011 3:17 pm Post subject: Re: I can't click my button. |
|
|
I guess I should have said that I tried putting the GUI.ProcessEvent in the loop already. What happens is that it goes straight to the goodbye procedure even if I click the menu button. Is there something I'm missing? |
|
|
|
|
|
Tony
|
Posted: Sun Jan 02, 2011 3:56 pm Post subject: RE:I can\'t click my button. |
|
|
Yes.
Quote:
The loop runs continuously until GUI.Quit is called, whereupon GUI.ProcessEvent will return true and the loop will exit.
Edit: to be clear, once GUI.Quit is called, _any_ GUI.ProcessEvent will exit. The intention is that you drop all the way down and end the program. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
doubleN
|
Posted: Sun Jan 02, 2011 4:07 pm Post subject: Re: I can't click my button. |
|
|
But nowhere in my display procedure does it quit, so it should go to main menu. And if you're talking about the first loop, it does exit, in this code(userInput) The main Menu sends it here.
Turing: |
proc userInput
title
locate (5, 1)
%Asking for and getting the user's guess
put "Enter a number between 25 and 75: " ..
get guess
%Opens a window which tells the user to enter another number if number is out of bounds
if guess < 25 or guess > 75 then
errorWindow
userInput
end if
GUI.Quit
end userInput
|
Here's my new Main Program
|
|
|
|
|
|
doubleN
|
Posted: Sun Jan 02, 2011 4:11 pm Post subject: Re: I can't click my button. |
|
|
Then again, the new main Program will send the user to display even if the user quits. Well, looks like I have to rewrite a lot of stuff here then.
Edit: Okay then, I suppose I understand.
If it has to just drop down and end, what I really need is a way for the program to continue from userInput to display. I can't call the display in userInput because display has to be declared first. I can't reverse their positions either because the main menu is in between these two procedures, and main menu calls userInput. What the heck do I do? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
doubleN
|
Posted: Sun Jan 02, 2011 4:26 pm Post subject: Re: I can't click my button. |
|
|
You probably won't see my upper post so bump |
|
|
|
|
|
Tony
|
Posted: Sun Jan 02, 2011 5:07 pm Post subject: RE:I can\'t click my button. |
|
|
code: |
introduction
loop
exit when GUI.ProcessEvent
end loop
display
|
GUI has to quit for the first loop to exit and to start the display procedure. At that point, GUI will no longer work. Think of other ways of exiting a loop, without calling Quit.
code: |
loop
exit when GUI.ProcessEvent
exit when ...
end loop
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
doubleN
|
Posted: Mon Jan 03, 2011 8:38 pm Post subject: Re: I can't click my button. |
|
|
Well, thanks for helping, I figured it out |
|
|
|
|
|
gtbgtb
|
Posted: Tue Jan 04, 2011 2:03 pm Post subject: RE:I can\'t click my button. |
|
|
Are you in Evil D's Class? Your prgramming style seems to be. Which class are you in? What period? |
|
|
|
|
|
|
|