GUI running with loop
Author |
Message |
Abdiwahab
|
Posted: Mon Jan 14, 2008 8:00 pm Post subject: GUI running with loop |
|
|
I have a computer game ISP due Wednesday. So far, I got everything down fine, but I'm stuck now. My teacher said that we had to include a button in the game screens that goes back to main menu if the user wants to opt out of playing and return to the start screen. But what sucks is my GUI doesn't work cuz I have a loop running in the same procedure. Can anyone help me?
Turing: |
procedure l1
title
level := 1
qolor (1) := 150
qolor (2) := 50
qolor (3) := 50
qolor (4) := 150
next := 0
counter := 0
drawfillbox (50, 320, 100, 370, grey)
drawfillbox (150, 320, 200, 370, grey)
drawfillbox (250, 320, 300, 370, grey)
drawfillbox (350, 320, 400, 370, grey)
drawfillbox (540, 320, 640, 370, red)
Draw.Text ("GUESS", 560, 340, lhfont, white)
GUI.Show (menuButton )
GUI.Enable (menuButton )
loop
mousewhere (x, y, button )
if button = 1 and x > 540 and x < 640 and y > 320 and y < 370 then
counter := counter + 1
next := next + 55
checker
locate (24, 1)
if number = 4 then
put "You got it!"
pauseProgram
exit
else
put number, " pegs are in the right place. You have ", 5 - counter, " more tries left!"
end if
if counter = 5 and number not= 4 then
locate (24, 1)
put "Nope. Let's hope you do better in the next level."
pauseProgram
exit
end if
pauseProgram
drawfillbox (0, 0, 540, 34, white)
number := 0
end if
if button = 1 and y > 35 + next and y < 85 + next then
if x > 50 and x < 100 then
which := 1
change
elsif x > 150 and x < 200 then
which := 2
change
elsif x > 250 and x < 300 then
which := 3
change
elsif x > 350 and x < 400 then
which := 4
change
end if
end if
drawfillbox (50, 35 + next, 100, 85 + next, kolor (1))
drawfillbox (150, 35 + next, 200, 85 + next, kolor (2))
drawfillbox (250, 35 + next, 300, 85 + next, kolor (3))
drawfillbox (350, 35 + next, 400, 85 + next, kolor (4))
delay (100)
end loop
next := 0
counter := 0
number := 0
for z : 1 .. 8
kolor (z ) := 50
end for
l2
end l1
|
^That doesn't work. Is there anyway to make a button and a loop run at the same time without the button just uselessly sitting there? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Jan 14, 2008 8:24 pm Post subject: RE:GUI running with loop |
|
|
You need to place GUI.ProcessEvents inside the loop, so that it can process any events that might happen to GUI (such as mouse clicks, etc). |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Abdiwahab
|
Posted: Mon Jan 14, 2008 9:06 pm Post subject: Re: GUI running with loop |
|
|
Thanks Tony! I added this:
...but this loop gets in the way of the other loop and makes it so that the other loop isn't displayed.
How can u make it so that the two loops run at the same time? |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Jan 14, 2008 9:35 pm Post subject: RE:GUI running with loop |
|
|
why not just combine the contents of the loops together? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Abdiwahab
|
Posted: Mon Jan 14, 2008 9:49 pm Post subject: RE:GUI running with loop |
|
|
Anywhere I put it, its still waiting for the GUI to be clicked before doing anything else. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Jan 14, 2008 9:55 pm Post subject: RE:GUI running with loop |
|
|
that would largely depend on your logic flow. Try to step through your program, one line at a time, and see how loops and if-conditions affect the flow. If you get stuck anywhere (for example, loop doesn't exit, or the program is waiting for user input), then that's the problem. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Abdiwahab
|
Posted: Mon Jan 14, 2008 10:00 pm Post subject: RE:GUI running with loop |
|
|
LOL just as I sent the last reply I noticed that if-statements work even better then exit when which is what u said right now:
Thanks for all your help
Compsci is awesome ![Very Happy Very Happy](images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
|
|