Author |
Message |
Guest
|
Posted: Thu May 25, 2006 6:04 pm Post subject: Returning to a Procedure |
|
|
Is it possible to say, have this:
code: |
proc MAP_1
if (x = true) then
MAP_2
end MAP_1
proc MAP_2
if (x = false) then
MAP_1
end MAP_2
|
I really need this to help me in my RPG to make it so when I touch the town I enter it, then when I touch the gate to the outside, I come back out. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
TheOneTrueGod
![](http://www.drmcninja.com/images/mcninjab3.jpg)
|
Posted: Thu May 25, 2006 6:17 pm Post subject: (No subject) |
|
|
This is the circular dependance problem. No, in a language like turing, It is not possible to have that directly. HOWEVER, there are ways to simulate things like this. Read Cervantes' topic in the tutorials about turing as a functional language. You can simulate a procedure using a function. There are a couple other options, depending on what you need done.
#1) You could use recursion,
code: |
procedure MAP_1 (x : int)
if x > 0 then
MAP_1 (x - 1)
end if
end MAP_1
|
#2) You could have a variable that returns from the procedure, and tells you if you need to call the second procedure or not.
#3) Use a different programming language (One that is compiled not interpreted [I believe I said that right... someone correct me if not]) |
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Thu May 25, 2006 6:39 pm Post subject: Re: Returning to a Procedure |
|
|
vahnx wrote: Is it possible to say, have this:
code: |
proc MAP_1
if (x = true) then
MAP_2
end MAP_1
proc MAP_2
if (x = false) then
MAP_1
end MAP_2
|
I really need this to help me in my RPG to make it so when I touch the town I enter it, then when I touch the gate to the outside, I come back out.
well you need an exit condition on one of the proc.. so that it doesnt get stuck in a circle... |
|
|
|
|
![](images/spacer.gif) |
TheOneTrueGod
![](http://www.drmcninja.com/images/mcninjab3.jpg)
|
Posted: Thu May 25, 2006 6:45 pm Post subject: (No subject) |
|
|
lol, mystic vegeta, its not possible. It'll give you the error "MAP_2" has not been declared. Turing works linearly. Ready my previous post, and try it out if you don't believe me ![Razz Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Thu May 25, 2006 6:51 pm Post subject: (No subject) |
|
|
I thought you were familiar with forward and body procs...
code: | var x : boolean
forward proc MAP_2
proc MAP_1
if (x = true) then
MAP_2
end if
end MAP_1
body proc MAP_2
if (x = false) then
MAP_1
end if
end MAP_2
|
|
|
|
|
|
![](images/spacer.gif) |
TheOneTrueGod
![](http://www.drmcninja.com/images/mcninjab3.jpg)
|
Posted: Thu May 25, 2006 7:41 pm Post subject: (No subject) |
|
|
lol, nope. I've used em in classes, but only to have multiple copies of the same procedure . (Neither was vahnx. You gotta explain that when helping ) |
|
|
|
|
![](images/spacer.gif) |
Guest
|
Posted: Thu May 25, 2006 8:40 pm Post subject: (No subject) |
|
|
Thanks so much MysticVegeta! I've been wondering this since i started Turing like 4/5ths a semester ago. You truly are a programming god. Did I ever tell you that.... I...... Love you.... (*kiss*)
Also, is there a way to also transfer a variable from inside that body procedure? |
|
|
|
|
![](images/spacer.gif) |
TheOneTrueGod
![](http://www.drmcninja.com/images/mcninjab3.jpg)
|
Posted: Thu May 25, 2006 9:03 pm Post subject: (No subject) |
|
|
either global variables or
forward proc MAP_2 (var x : int, y : boolean /*etc*/) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Fri May 26, 2006 2:12 pm Post subject: (No subject) |
|
|
vahnx wrote: Also, is there a way to also transfer a variable from inside that body procedure? Do you mean transfer a variable from inside to the outside or from outside to the inside..
Cause if its from outside to inside then truegod's post will help you else if its from inside to outside then you need "functions" that return a value like..
code: | fcn square (x : int) : int
return x**2
end square
put square (2) % Outputs 4
var squaredNumber := square (someNumber) % Transfers the value from inside the function to the outside by storing the returning value in "squaredNumber" variable.
|
|
|
|
|
|
![](images/spacer.gif) |
Guest
|
Posted: Sat May 27, 2006 8:16 am Post subject: (No subject) |
|
|
Yeah for my game I just made it a global variable, so it doesnt really matter now. And I could use () probably. |
|
|
|
|
![](images/spacer.gif) |
|