I'm have some trouble declaring procedures after they are needed (CLICK TO READ MORE!)
Author |
Message |
monsterkid
|
Posted: Mon Nov 17, 2008 7:25 pm Post subject: I'm have some trouble declaring procedures after they are needed (CLICK TO READ MORE!) |
|
|
I'm making a gui menu for my RPG game and i have 4 menu options to choose from:"new game", "load game", "options", and "quit". I have all of the buttons made im just making the procedures. im working on my quit button right now and i have 1 of 2 choices to choose from when i execute it...yes and no, when it asks the user if they're sure. now, this is where I get the problem. I know there is a way to fix this its just a matter of time. When the user clicks no, i want them to be directed back to the main menu which i already have as a procedure. it wont let me do this because i need the main menu declared as a procedure before asking for it (check) but i hant have the nobutton procedure before it but thats where i need it or else it wont recognize the procedure/any variables in it as declared variables. please give me a hand, im new with this stuff. click the link below for the program its nothin but w/e.
Description: |
|
Download |
Filename: |
RPG game.t |
Filesize: |
2.16 KB |
Downloaded: |
71 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Mon Nov 17, 2008 7:51 pm Post subject: RE:I\'m have some trouble declaring procedures after they are needed (CLICK TO READ MORE!) |
|
|
Well, variables declared in a procedure are not recognized anywhere else, no matter where the procedure is in the code. Typically, the menu is the last procedure created, as it calls up the other procedures that call up other procedures, etc. The 'are you sure you want to quit' bit doesn't even need to be in a procedure. if they select 'quit', enter a loop with two buttons (yes/no). if they select 'yes', then quit (actually type 'quit', it terminates the program), if they select no, exit the loop, which will return you to the menu.
code: |
proc menu
%if button 'quit' clicked then
loop
if %button 'yes' clicked then
quit
end if
exit when %button 'no' clicked
end loop
end menu
|
|
|
|
|
|
|
TheGuardian001
|
Posted: Tue Nov 18, 2008 3:27 pm Post subject: Re: I'm have some trouble declaring procedures after they are needed (CLICK TO READ MORE!) |
|
|
the easiest way to make sure that you have all procedures declared is to use the forward and body commands. these allow you to declare a function or procedure right at the start, but not actually define their contents until later. so if you need a procedure to be available to everything, but also call upon other procedures (or if two procedures need to call on each other), declare all procedures right away with forward, then define their bodies later
Turing: |
forward procedure double(n : int)
double(1)
body procedure double
put n * 2
end double
|
|
|
|
|
|
|
monsterkid
|
Posted: Wed Nov 19, 2008 12:40 am Post subject: Re: I'm have some trouble declaring procedures after they are needed (CLICK TO READ MORE!) |
|
|
Thanks guys thats exactly what i was looking for.
thanks alot!
|
|
|
|
|
|
|
|