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

Username:   Password: 
 RegisterRegister   
 How to make an if command execute a procedure?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JesseM




PostPosted: Sat Jan 25, 2014 12:00 pm   Post subject: How to make an if command execute a procedure?

What is it you are trying to achieve?
I am trying to make a short text adventure game with Turing. I was taught the barebones basics by someone, and I taught myself about boolean variables and procedures. My plan was to make an individual procedure for each "room" in the game, with lines of code that link them together. For instance, I made a variable called input that defines what action the player wants to do, and I want to set it so that if input is equal to "forward" or "left" then it will run the procedure for the room ahead or to the left or whatever.


What is the problem you are having?
Turing thinks the names of the procedures I have created are the names of undefined variables, not procedures, and as such refuses to actually run them.


Describe what you have tried to solve this problem
Not much because I learn what I know about Turing like three days ago. I tried cutting out each individual procedure to see if they worked, which they did, and then I tried writing an all new, simpler version of the code to test what I wanted to do. That didn't work so it must be where the problem lies. But I don't really know how to tell Turing what I want it to do.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


%This the the code I wrote to test my idea%
var input : boolean

procedure one
put "hello!"
loop
get input
if input = true then put "advancing"
two
end if
if input = false then put "remaining"
end if
exit when input = true
end loop
end one

procedure two
put " area two"
loop
get input
if input = true then put "remaining"
end if
if input = false then put "returning"
one
end if
exit when input = false
end loop
end two

one



%This is the code I wrote for the actual game%
put "You and a band of other adventurers were exploring a dungeon when the "
put "entrance collapsed! Only you made it out, but your survival came at the "
put "expense of your equipment! Now, you find yourself stranded in a strange "
put "cave system, with only one goal: find a way out!"
    %VARIABLES
    var input : string
    var knife : boolean
    var potion : boolean
    var key : boolean
    var sword : boolean
    var helmet : boolean
    var gold : int
    var maxhealth : int
    var currenthealth : int
    var maxstamina : int
    var currentstamina : int
    var torch : boolean
    var gottenkey : boolean
    gottenkey := false
    torch := false
    knife := false
    potion := false
    key :=false
    sword := false
    helmet := false
    gold :=0
    maxhealth:= 20   
    currenthealth := 20
    maxstamina := 10     
    currentstamina := 10
%Procedures
%Tutorial segment
procedure entrance
loop
get input
if input = "look" then put "Behind you is a pile of rubble which used to be the "
    put "entrance to the dungeon. In front of you is the cave mouth, shrouded in inky "
    put "blackness. To your right there flickers a dim torch. (type help for help)"
end if
if input = "inv" then put "You are carrying:"
if gold >0 then put gold, " gold pieces"
if knife = true then put "a knife"
if potion = true then put "a potion"
if key = true then put "a key"
if sword = true then put "a sword"
if helmet = true then put "a helmet"
end if
end if
end if
end if
end if
end if
end if
if input = "get torch" or input ="torch" then put "you pick up the dim torch"
torch :=true
end if
if input = "go forward" or input ="forward" and torch = false then put "The dark makes you uneasy"
end if
if input = "go forward" or input = "forward" and torch = true then put "you advance forward"
end if
if input = "help" then put "inv opens inventory, look looks around, get (object) picks up an object,"
put " go (direction) or just (direction) will move in that direction, and nav open the navigation menu."
end if
exit when input = "go forward" or input = "forward" and torch = true
end loop
end entrance

%tutorial area hallway%
procedure firsthall
put "You are in a long, smooth hallway carved into the rock of the cave. "
put "Immediately to your left is a large doorway. Ahead and to your right is another"
put "gaping hole in the wall. Straight ahead is a large gate with an oversized lock"
put "on it."
loop
get input

if input = "look" then put "You are in a long, smooth hallway carved into the rock of the cave. "
put "Immediately to your left is a large doorway. Ahead and to your right is another"
put "gaping hole in the wall. Straight ahead is a large gate with an oversized lock"
put "on it."
end if

if input = "inv" then put "You are carrying:"
if gold >0 then put gold, " gold pieces"
if knife = true then put "a knife"
if potion = true then put "a potion"
if key = true then put "a key"
if sword = true then put "a sword"
if helmet = true then put "a helmet"
end if
end if
end if
end if
end if
end if
end if

if input = "help" then put "inv opens inventory, look looks around, get (object) picks up an object,"
put " go (direction) or just (direction) will move in that direction, and nav open the navigation menu."
end if

if input = "left" or input = "go left" then keyroomONE
if input = "right" or input = "go right" then tut_goldroom
if input = "forward" or input = "go forward" and key = false then tut_gate_nokey
if input = "forward" or input = "go forward" and key = true then tut_gate_key
end if
end if
end if
end if

exit when input = "forward" or input = "go forward" and key = true
end loop
end firsthall


%First Keyroom%
procedure keyroomONE
put "The room to your left is carved equally smoothly out of the solid rock. The room seems completely"
put "barren at first, but the light of your torch reflects of a small object in the center of the room."
put "It is a key!"
loop
get input

if input = "look" then put "The room to your left is carved equally smoothly out of the solid rock. The room seems completely"
put "barren at first, but the light of your torch reflects of a small object in the center of the room."
put "It is a key!"
end if

if input = "look key" then put "It is hard to see from the doorway of the room, but the key seems gold or brass, and about the"
put "right size to fit the lock on the gate you saw earlier."
end if

if input = "inv" then put "You are carrying:"
if gold >0 then put gold, " gold pieces"
if knife = true then put "a knife"
if potion = true then put "a potion"
if key = true then put "a key"
if sword = true then put "a sword"
if helmet = true then put "a helmet"
end if
end if
end if
end if
end if
end if
end if

if input = "help" then put "inv opens inventory, look looks around, get (object) picks up an object,"
put " go (direction) or just (direction) will move in that direction, and nav open the navigation menu."
end if

if input = "key" or input = "get key" and gottenkey = false then put "You notice the key is strangely warm as you slip it into your"
put "pocket. Gained ONE KEY!"
gottenkey := true
end if

if input = "key" or input = "get key" and gottenkey = true then put "You already have the key."
end if

if input = "go back" or input = "back" or input = "return" or input = "door" then firsthall
end if

exit when input = "go back" or input = "back" or input = "return" or input = "door"
end loop
end keyroomONE

%opening the gate with the key%
procedure tut_gate_key
put "The key slides in easily and the gate vanishes. You head forward, eager to escape,"
put "but when you look behind you there is naught but a solid stone wall."
main_entrance
end tut_gate_key



Please specify what version of Turing you are using
I am using Turing 4.1.1


One last thing- I know that a bunch of procedures are undefined in that code, it's still a work in progress, but I wasn't getting the error message I expected from the program which led to me finding this issue.
Sponsor
Sponsor
Sponsor
sponsor
evildaddy911




PostPosted: Sat Jan 25, 2014 12:46 pm   Post subject: RE:How to make an if command execute a procedure?

in turing, you have to declare EVERYTHING before you reference them. what you are trying to do is reference procedure 'two' in procedure 'one', which happens to be placed just before 'two'. the obvious fix would be swapping the 2, making
Turing:

procedure two
    ...
end two
procedure one
   ...
end one

however, you are calling procedure 'one' from procedure 'two', so you will still get the same error.
fortunately, there is a solution, check out deferred, what it does is allows you to declare a procedure/method, then define what it will do later (using body). just remember to give them bodies before they get called
JesseM




PostPosted: Sun Jan 26, 2014 1:48 pm   Post subject: Re: How to make an if command execute a procedure?

Thank you!
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  [ 3 Posts ]
Jump to:   


Style:  
Search: