Computer Science Canada Can a procedure (for a GUI module) work within an if statement? |
Author: | vdemons [ 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! |
Author: | apython1992 [ 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. |
Author: | vdemons [ 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? |
Author: | apython1992 [ 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. |
Author: | vdemons [ 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)? |
Author: | vdemons [ 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? |
Author: | Tony [ 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? |
Author: | vdemons [ 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 |
Author: | Tony [ 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). |
Author: | apython1992 [ 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. |
Author: | vdemons [ 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? |
Author: | Tony [ Sat May 21, 2011 5:24 pm ] | ||||||
Post subject: | RE:Can a procedure (for a GUI module) work within an if statement? | ||||||
nothing happens
procedure was always called
procedure called only if variable bar was set to true |
Author: | vdemons [ 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 |