Author |
Message |
vdemons
|
Posted: Sat May 21, 2011 11:01 am Post subject: Can a procedure (for a GUI module) work within an if statement? |
|
|
I am suppose to make a game for my class, but being the over achiever I am I made two. Now I want to put the two together to make 2 games in one. The problem is that I used a GUI module in both my programs. I know they don't work in loops but do they work in if statements because I plan to make my own button (click on a box to enable one game, click on another box to play another game). I would like to know if its possible to do such a thing if not is there any other method?
Please and Thank you in Advance! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
apython1992
![](http://compsci.ca/v3/uploads/user_avatars/17001640684d87a16bb8fbb.jpg)
|
Posted: Sat May 21, 2011 2:55 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
Yes. Your front-end GUI will be the interface that selects a game, and you can use simple GUI logic to control this. |
|
|
|
|
![](images/spacer.gif) |
vdemons
|
Posted: Sat May 21, 2011 4:22 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
Front - end GUI? I have never heard of that, what is it? |
|
|
|
|
![](images/spacer.gif) |
apython1992
![](http://compsci.ca/v3/uploads/user_avatars/17001640684d87a16bb8fbb.jpg)
|
Posted: Sat May 21, 2011 4:37 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
By front-end I just mean something that a user will interface with - like this GUI. |
|
|
|
|
![](images/spacer.gif) |
vdemons
|
Posted: Sat May 21, 2011 4:42 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
So how would I use that in selecting my game(s)? |
|
|
|
|
![](images/spacer.gif) |
vdemons
|
Posted: Sat May 21, 2011 4:54 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
Because I used a GUI example from the help guide put it under an if statement and gave me an error, so what do I do? |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Sat May 21, 2011 4:59 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
What kind of an error? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
vdemons
|
Posted: Sat May 21, 2011 5:11 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
"Procedure's may only be declared at the program, module, or monitor level."
The code (made as an example):
import GUI
var d : int := 1
if d = 1 then
procedure DrawRandomCircle
var r : int := Rand.Int (20, 50)
var x : int := Rand.Int (r, maxx - r)
var y : int := Rand.Int (r, maxy - r)
var c : int := Rand.Int (0, maxcolor)
Draw.FillOval (x, y, r, r, c)
% In case we drew over the buttons, redraw them.
GUI.Refresh
end DrawRandomCircle
View.Set ("graphics:300;200,nobuttonbar")
var draw : int := GUI.CreateButtonFull (50, 10, 0, "Draw Circle",
DrawRandomCircle, 0, '^D', true)
var quitBtn : int := GUI.CreateButton (200, 10, 0, "Quit", GUI.Quit)
loop
exit when GUI.ProcessEvent
end loop
end if |
|
|
|
|
![](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: Sat May 21, 2011 5:15 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
You can't declare procedures inside another block of code (with an exception of it being a module or monitor). |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
apython1992
![](http://compsci.ca/v3/uploads/user_avatars/17001640684d87a16bb8fbb.jpg)
|
Posted: Sat May 21, 2011 5:18 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
You may be getting confused about the difference between defining procedures and actually using them. If you define a procedure, it won't actually do anything until you call it. Define the procedures that invoke both games, but let the if statement control which procedure is actually called. |
|
|
|
|
![](images/spacer.gif) |
vdemons
|
Posted: Sat May 21, 2011 5:20 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
I am sorry but I don't know what you mean, can you give me an example? |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Sat May 21, 2011 5:24 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
code: |
procedure foo
put "hi"
end foo
|
nothing happens
code: |
procedure foo
put "hi"
end foo
foo
|
procedure was always called
code: |
var bar : boolean := true
procedure foo
put "hi"
end foo
if bar then
foo
end if
|
procedure called only if variable bar was set to true |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
vdemons
|
Posted: Sat May 21, 2011 7:37 pm Post subject: RE:Can a procedure (for a GUI module) work within an if statement? |
|
|
i got it ty |
|
|
|
|
![](images/spacer.gif) |
|