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

Username:   Password: 
 RegisterRegister   
 I'm have some trouble declaring procedures after they are needed (CLICK TO READ MORE!)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
monsterkid




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


RPG game.t
 Description:
RPG GAME

Download
 Filename:  RPG game.t
 Filesize:  2.16 KB
 Downloaded:  71 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Insectoid




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




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




PostPosted: 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!
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  [ 4 Posts ]
Jump to:   


Style:  
Search: