Exiting Loops and buttons
Author |
Message |
sasha
|
Posted: Wed Jan 13, 2010 9:27 pm Post subject: Exiting Loops and buttons |
|
|
What is it you are trying to achieve?
I am trying to get from one page (easy1) to the display page.
What is the problem you are having?
The button doesnt work at all
Describe what you have tried to solve this problem
I'm not sure what to do
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
import GUI
var mainWinID : int := Window.Open ("position:100;100,graphics:600;400")
var font : int
var font1 : int
var finished : boolean := false
var gameStart : boolean := false
var menuButton, quitButton, playButton, helpButton, doneButton, backMainMenu, easyButton, hardButton, hardOption1, hardOption2, hardOption3, hardOption4, hardOption5, easyOption1, easyOption2,
easyOption3, easyOption4, easyOption5 : int := 0
var gameInput : string
var guess, answer : string
var pictureID : int
var key : string (1)
procedure easy1
%Input
locate (5, 36)
put "Please enter any words you can find:"
%Frame for letters - incrustation
drawbox (50, 80, 248, 320, blue)
drawline (50, 240, 248, 240, blue)
drawline (50, 160, 248, 160, blue)
drawline (100, 320, 100, 80, blue)
drawline (150, 320, 150, 80, blue)
drawline (200, 320, 200, 80, blue)
%Frame for answers - First word crust
drawbox (278, 235, 308, 265, 40)
drawbox (308, 235, 338, 265, 42)
drawbox (338, 235, 368, 265, 44)
drawbox (368, 235, 398, 265, 47)
drawbox (398, 235, 428, 265, 77)
%tin
drawbox (448, 235, 478, 265, 40)
drawbox (478, 235, 508, 265, 42)
drawbox (508, 235, 538, 265, 77)
%rust
drawbox (278, 195, 308, 225, 40)
drawbox (308, 225, 338, 195, 44)
drawbox (338, 195, 368, 225, 47)
drawbox (368, 225, 398, 195, 77)
%trust
drawbox (448, 195, 478, 225, 40)
drawbox (478, 225, 508, 195, 42)
drawbox (508, 195, 538, 225, 44)
drawbox (538, 225, 568, 195, 47)
drawbox (568, 195, 598, 225, 77)
%stat
drawbox (278, 155, 308, 185, 40)
drawbox (308, 185, 338, 155, 44)
drawbox (338, 155, 368, 185, 47)
drawbox (368, 185, 398, 155, 77)
%run
drawbox (448, 155, 478, 185, 40)
drawbox (478, 185, 508, 155, 44)
drawbox (508, 155, 538, 185, 77)
%son
drawbox (278, 115, 308, 145, 40)
drawbox (308, 145, 338, 115, 44)
drawbox (338, 115, 368, 145, 77)
%sun
drawbox (278, 75, 308, 105, 40)
drawbox (308, 105, 338, 75, 44)
drawbox (338, 75, 368, 105, 77)
%tan
drawbox (278, 35, 308, 65, 40)
drawbox (308, 65, 338, 35, 44)
drawbox (338, 35, 368, 65, 77)
var font1, font2 : int
font1 := Font.New ("Palatino:24:bold,italic")
Font.Draw ("C", 60, 280, font1, brightred)
Font.Draw ("R", 110, 280, font1, brightred)
Font.Draw ("N", 160, 280, font1, brightred)
Font.Draw ("I", 210, 280, font1, brightred)
Font.Draw ("U", 60, 190, font1, brightred)
Font.Draw ("S", 110, 190, font1, brightred)
Font.Draw ("T", 160, 190, font1, brightred)
Font.Draw ("A", 210, 190, font1, brightred)
Font.Draw ("O", 60, 90, font1, brightred)
Font.Draw ("N", 110, 90, font1, brightred)
Font.Draw ("T", 160, 90, font1, brightred)
Font.Draw ("I", 210, 90, font1, brightred)
%User inputs their guess
loop
locate (7, 36)
get guess
if guess = "crust" or guess = "CRUST" or guess = "Crust" then
Font.Draw ("C R U S T", 280, 240, font1, 12)
elsif guess = "tin" or guess = "TIN" or guess = "Tin" then
Font.Draw ("T I N", 448, 239, font1, 12)
elsif guess = "rust" or guess = "RUST" or guess = "Rust" then
Font.Draw ("R U S T", 278, 198, font1, 12)
elsif guess = "stat" or guess = "STAT" or guess = "Stat" then
Font.Draw ("S T A T", 278, 160, font1, 12)
elsif guess = "son" or guess = "SON" or guess = "Stat" then
Font.Draw ("S O N", 278, 115, font1, 12)
elsif guess = "sun" or guess = "SUN" or guess = "Sun" then
Font.Draw ("S U N", 278, 75, font1, 12)
elsif guess = "tan" or guess = "TAN" or guess = "Tan" then
Font.Draw ("T A N ", 278, 35, font1, 12)
elsif guess = "trust" or guess = "TRUST" or guess = "Trust" then
Font.Draw ("T R U S T", 448, 195, font1, 12)
elsif guess = "run" or guess = "RUN" or guess = "Run" then
Font.Draw ("R U N", 448, 155, font1, 12)
end if
end loop
GUI.Show (doneButton)
end easy1
procedure display
locate (12, 33)
put "You win"
GUI.Show (menuButton)
end display
doneButton := GUI.CreateButtonFull (262, 10, 0, "DONE!", display, 0, '^A', true)
easy1
display
[/syntax]
Please specify what version of Turing you are using
4.0.5 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TerranceN
|
Posted: Wed Jan 13, 2010 10:52 pm Post subject: Re: Exiting Loops and buttons |
|
|
In order for the GUI to work you need to have a loop like this
Turing: | loop % GUI update loop
% other updates
exit when GUI.ProcessEvent % this updates the GUI
end loop |
So instead of calling easy1 and display, put them into a loop like this (actually since display is supposed to be called by the button, dont call it).
Also, 'get' stops the program, so while you are waiting for input the button will not be updated, and therefore will not respond, you can sort of get around this with the hasch function like so
Turing: | loop
if (hasch()) then
var input : string := ""
get input
put input
end if
exit when GUI.ProcessEvent % this updates the GUI
end loop |
hasch returns true if there is a key waiting to be processed, therefore this will not wait for input until a key has been pressed, but while entering input your button will not respond.
But if you combine the hasch trick with getch(which also stops your program, which is why you still need hasch), you can get input and your buttons will work too. Look up getch in the Turing Documentation, also you will notice you can only get one character with getch. If you use a global string, and increment the string with the inputted character (stringName += getchInputName) you can get as much text input as you want. And you can also compare the getch character to key codes, specifically KEY_ENTER in order to tell if the user has pressed enter to input their text.
Also in your easy1 procedure since there is an endless loop, if you called it in the GUI update loop it would never reach GUI.ProcessEvent, so remove the loop from that procedure, but it will still loop because of the GUI update loop.
I hope this helped. |
|
|
|
|
|
sasha
|
Posted: Thu Jan 14, 2010 8:36 pm Post subject: RE:Exiting Loops and buttons |
|
|
Thanks! |
|
|
|
|
|
|
|