Calling a procedure help!
Author |
Message |
tecnikal
|
Posted: Tue Jun 02, 2009 2:24 pm Post subject: Calling a procedure help! |
|
|
The title might be a little misleading but bare with me
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?
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
(2) GRIDLINES AND MENU BOTTOm.t |
Filesize: |
54.62 KB |
Downloaded: |
62 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
tecnikal
|
Posted: Tue Jun 02, 2009 3:58 pm Post subject: RE:Calling a procedure help! |
|
|
Thanks so much. you understood my problem completely
Got it working now
compsci rocks haha
|
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
|
|