Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Can a procedure (for a GUI module) work within an if statement?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
vdemons




PostPosted: 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!
Sponsor
Sponsor
Sponsor
sponsor
apython1992




PostPosted: 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.
vdemons




PostPosted: 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?
apython1992




PostPosted: 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.
vdemons




PostPosted: 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)?
vdemons




PostPosted: 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?
Tony




PostPosted: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
apython1992




PostPosted: 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.
vdemons




PostPosted: 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?
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: