

-----------------------------------

ipwnuha

Wed Mar 28, 2012 1:19 pm


Procedure Problems

-----------------------------------

What is it you are trying to achieve?
Text adventure game with procedures.


What is the problem you are having?
I need to call upon procedures but am having problems with them not being declared. is there a way around the "procedure not declared" problem?



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
This is the code i am using



var choice, key1, key2, sword: int
sword:= 0
key1:= 0
key2:=0
procedure east
cls 
put "You enter the room and look around startled you turn around and see the door behind you close better hope there is another way out!"
put "Choose the number of what you want to do"
put "1. open door"
get choice
 if key2 = 1
  then put "you leave the room, and see the outside and the sun. goodjob you have completed this adventure!"
 elsif key2 = 0
  then put "you aproach the door and see a lock. you try everything in your inventory but fail. You later starve."
  put "GAME OVER"
end if
end east
procedure north
cls
put "After heading north you enter a small room, you catch site of a key"
put "hanging on the wall, however you also notice a BEAR. it is sleeping"
put "Choose the number of what you want to do"
put "1. Go south"
put "2. Attack the bear"
get choice
if choice = 1
 then center
elsif choice = 2
 then if sword = 0
  then put "You hurl yourself at the bear punching it wildly. it turns and slowly devours   you whole."
   put "you are dead"
  elsif sword = 1
   then put "you sneak up on the bear and hit it with the sword, it does no damage, the bear trying to impress somone eats your sword then turn on you, it soon dies of internal bleeding. good job! You grab the key off the wall and head south"
   center2
end if
end if
end north
procedure center
cls
put"You find yourself in a very simple room. there are corridors leading to the"
put"north, south, east and west. The brick is plain and you see nothing"
put"worthwhile near you."
put "Choose the number of what you want to do"
put "1. Go North"
put "2. Go East"
put "3. Go West"
put "4. Go South"
get choice
if choice = 1
 then north
elsif choice = 2
 then  east
elsif choice = 3
 then 
elsif choice = 4
 then 
else put "I dont understand"
 center
end if
end center
center



Please specify what version of Turing you are using
I am using version 4.1 for turing

Aditional note. this is my first post and i am sorry for any formatting problems.


-----------------------------------

Dreadnought

Wed Mar 28, 2012 2:05 pm


Re: Procedure Problems

-----------------------------------

The problem is that you have procedures that call each other in a circular way. To do this you must use forward proc P2

proc P1
P2
end P1

body proc P2
P1
end P2
% P1 calls P2 which calls P1 and the cycle repeats


-----------------------------------

ipwnuha

Wed Mar 28, 2012 6:05 pm


RE:Procedure Problems

-----------------------------------

Thank you very much that fixed everything.


-----------------------------------

Tony

Wed Mar 28, 2012 6:32 pm


RE:Procedure Problems

-----------------------------------

unlikely to actually happen if you require user input in every procedure, but in long-enough games you run the risk of stack overflow exception (as there is no tail-end recursive call optimization -- that is, you just keep on building up a stack of new procedure calls on top of each other, never exiting from them).

