Buttons Help
Author |
Message |
elmocookies
|
Posted: Mon Jan 01, 2007 2:07 pm Post subject: Buttons Help |
|
|
I have created a program which uses buttons to navigate. The buttons appear in some procedures but they dont work.
Here what I have so far.
code: |
%Set screen up
import GUI
setscreen ("nocursor")
setscreen ("noecho")
% Global Declaration Section
var number : int % the guess of the user
var answer : int % the random number the computer chooses
var triesleft : int := 3 % amount of tries the user has left from the original three
var winID1 := Window.Open ("position:300;300, graphics:400;300") % the main window with the game in it
var menu : int :=0 % the main menu button variable
var quitBtn :int:=0 % the exit button variable
var playGame :int :=0 % the play game variable
% Program Title
procedure title
locate (1, 19)
put "Guessing Game"
end title
% Program Introduction
procedure intro
cls
title
locate (3, 1)
put "This program will allow you to guess a number that the computer is thinking of!"
GUI.Refresh
end intro
% Random Number
procedure randNum
randint (answer, 10, 65)
end randNum
% Goodbye
procedure goodbye
cls
title
locate (5, 22)
put "Credits"
locate (10, 13)
put ""
locate (14, 14)
put ""
delay (6000)
cls
locate (12, 15)
put "Thank You For Playing!"
delay (2000)
Window.Close (winID1) % closes the main window
end goodbye
% Window 2
procedure drawWindow2
var winID2 := Window.Open ("position:200;200, graphics:300;100") % the error trap window
locate (1, 1)
put "Invalid Number! Your guess has to be between 10 and 64."
locate (4, 1)
put "Press any key to continue" ..
loop
exit when hasch
end loop
Window.Close (winID2) % closes error trap window
end drawWindow2
% UserInput
procedure userInput
cls
title
locate (5, 1)
put "Guess a number between 10 and 65: " ..
get number
if number < 10 or number > 65 then
drawWindow2 % opens error trap window
userInput
elsif number = answer then
title
locate (12, 9)
put "Congratulations! You guessed it!"
else
if triesleft = 0 then
cls
title
locate (11, 21)
put "YOU LOSE!"
locate (13, 20)
put "GAME OVER!"
end if
end if
end userInput
% Main Menu
procedure mainMenu
cls
title
GUI.Refresh
end mainMenu
% Display
procedure display
cls
title
locate (10, 6)
put "The last number that you guessed was: ", number ..
locate (14, 13)
put "The correct answer is: ", answer
delay (2000)
GUI.Refresh
end display
% Processing and Output
procedure output
cls
title
display
locate (5, 1)
put "The answer is ", answer
end output
% Main Game
procedure mainGame
randNum
loop
exit when triesleft = 0
userInput
if number = answer then
locate (11, 36)
put "Good Job!"
exit
else
locate (8, 1)
put "Thats wrong!"
triesleft := triesleft - 1
put "Guesses remaining: ", triesleft
delay (2000)
end if
end loop
cls
display
end mainGame
%Buttons
menu := GUI.CreateButtonFull (125,150,150, "Main Menu", mainMenu, 0, '^M', false)
quitBtn := GUI.CreateButtonFull (125, 100, 150, "Exit", goodbye, 0,KEY_ESC, false)
playGame := GUI.CreateButtonFull (125,200,150, "Play Guessing Game", mainGame, 0, '^P' , false)
% Main Program
intro
mainMenu
% End of Program |
Any ideas as to how I can fix that? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
tridi
|
Posted: Mon Jan 01, 2007 5:32 pm Post subject: (No subject) |
|
|
I got your buttons to work =D
code: | menu := GUI.CreateButtonFull (125,150,150, "Main Menu", mainMenu, 0, '^M', false)
quitBtn := GUI.CreateButtonFull (125, 100, 150, "Exit", goodbye, 0,KEY_ESC, false)
playGame := GUI.CreateButtonFull (125,200,150, "Play Guessing Game", mainGame, 0, '^P' , false)
loop
exit when GUI.ProcessEvent
end loop |
add the three last lines after your buttons. The program still doesn't work properly, though. =| tell me when you're finished, i'm still trying to finish mine... |
|
|
|
|
![](images/spacer.gif) |
tridi
|
Posted: Mon Jan 01, 2007 5:46 pm Post subject: (No subject) |
|
|
Actually, instead of "GUI.Refresh" put GUI.Show (buttonname) instead. Then put the following code in each procedure that has a button.
code: | loop
exit when GUI.ProcessEvent
end loop |
|
|
|
|
|
![](images/spacer.gif) |
elmocookies
|
Posted: Mon Jan 01, 2007 9:10 pm Post subject: (No subject) |
|
|
That works, but when the program exits an error message appears saying:
An error was found in "WidgetModule.tu".
[/quote] |
|
|
|
|
![](images/spacer.gif) |
tridi
|
Posted: Mon Jan 01, 2007 9:14 pm Post subject: (No subject) |
|
|
Ya, I have the same problem. I asked the teacher about it, but she said she doesn't know what the problem is. I'm leaving it for now. |
|
|
|
|
![](images/spacer.gif) |
elmocookies
|
Posted: Mon Jan 01, 2007 9:23 pm Post subject: (No subject) |
|
|
Ok nevermind then I'm done that. Thanks. |
|
|
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: Mon Jan 01, 2007 9:36 pm Post subject: (No subject) |
|
|
I think that happens because when you cole the window the code is still in this loop: code: | loop
exit when GUI.ProcessEvent
end loop |
|
|
|
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: Mon Jan 01, 2007 9:37 pm Post subject: (No subject) |
|
|
you need some way of exiting it |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|