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

Username:   Password: 
 RegisterRegister   
 Calling a procedure help!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tecnikal




PostPosted: Tue Jun 02, 2009 2:24 pm   Post subject: Calling a procedure help!

The title might be a little misleading but bare with me Smile


Here is the basic structure of my code:


> Variables Set

> procedure PLAYER 1
-> PLAYER 1 wants to end their turn, call PLAYER2 procedure

> procedure PLAYER 2
-> PLAYER 2 wants to end their turn, call PLAYER1 procedure.


As you can see, player two has no problem. The problem is with Player 1. How can i call a procedure below?


is there another way of doing this?



(2) GRIDLINES AND MENU BOTTOm.t
 Description:

Download
 Filename:  (2) GRIDLINES AND MENU BOTTOm.t
 Filesize:  54.62 KB
 Downloaded:  62 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Tue Jun 02, 2009 3:13 pm   Post subject: Re: Calling a procedure help!

If i understand the question, you should look into the forward and body commands. They allow you to create the procedure at the start of your program, but not define the contents until later.

Example

Turing:

forward proc first

forward proc last

body proc first
    put "Hi, this is procedure 1!"
    last
end first

body proc last
    put "Hi! this is Procedure 2!"
end last

first


the contents of procedure first are allowed to call procedure last because last was declared earlier using forward.
tecnikal




PostPosted: Tue Jun 02, 2009 3:58 pm   Post subject: RE:Calling a procedure help!

Thanks so much. you understood my problem completely Smile


Got it working now




compsci rocks haha Smile
DemonWasp




PostPosted: Tue Jun 02, 2009 6:31 pm   Post subject: RE:Calling a procedure help!

While your program may work, there's a potential problem to this kind of solution, which is that there is a limit to the number of "nested" procedure calls you can do. This is because of something called the stack, and the fact that you will overflow it. Without getting into the long explanations ready for that, let me just say that the following is better:

Turing:

loop
    player1()  % Does NOT call player2
    player2()  % Does NOT call player1
end loop


It is still worth knowing how to use forward and body though, as they have other, more important, uses.
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: