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

Username:   Password: 
 RegisterRegister   
 Resetting variables
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Polopa




PostPosted: Sat Feb 18, 2012 4:53 pm   Post subject: Resetting variables

So i decided to make a text based game on turing for fun I'm relatively new to programming, only been doing it for a week)
and I've encountered a problem which I'm not quite sure how to fix.

I have all the essentials down, and have my main texts undo procedures to get them easily when i need to
However my only problem is, if you start in (for lack of better names) A, and your options are B C and D to go to.
and the first time this option comes up you choose B, if ever you get back to A then you can no longer choose any other directions but B.

So essentially what i need is a way to make the variables reset right after you assign them something so that you can get a different output when you use them again.

If anyone knows how to do this i would greatly appreciate it.
(Also, if you need the actual programming of the game to determine the problem, just ask and ill post it up here)

thanks in advance
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sat Feb 18, 2012 5:01 pm   Post subject: RE:Resetting variables

You need to define what 'reset' means. Once a variable is assigned a value, it will always have a value. You need to pick a specific value to be the reset value. For example, if your reset value is "0", then whenever you need to reset it, just add var_whatever := 0.
Aange10




PostPosted: Sat Feb 18, 2012 5:04 pm   Post subject: RE:Resetting variables

The easiest way to do is would be to have a procedure to reset the variables, and call it when you need it.


Turing:

proc resetVaraibles
   d := %Default value
   b := %Default value
   .
   .
   %etc.
end resetVariables
Polopa




PostPosted: Sat Feb 18, 2012 5:05 pm   Post subject: Re: Resetting variables

well i have it made so that the variables are strings, and when you put in a certain string (ie east) it causes the east output to come up, but if you go back west from there (the main point)
and instead you want to go west this time (rather than east) it still sends you east because the variable was already set (im assuming)

so essentially i want to make it so that when you enter it, it doesnt affect future choices of the same variable (if thats even possible)

do, you want me to post the script for it? so you can (hopefully) see the problem
Aange10




PostPosted: Sat Feb 18, 2012 5:09 pm   Post subject: RE:Resetting variables

No, it's fine.

It's possible, you just have to program it.

Why not default the variable to "null"?

Turing:

direction := "null"


Or to anything you want. Then when it comes time to get a new input, you can simply tell the program

Turing:

if currentDirection = "null" then
 % Get a new direction
  get currentDirection
end if
Polopa




PostPosted: Sat Feb 18, 2012 5:18 pm   Post subject: Re: Resetting variables

it's still doing the same thing D:

im just gonna copy it into here

var name:string
var fielddirection1:string
var houseaction1:string
var houseaction2:string
var streamaction1:string
var woodsaction1:string

proc reset
fielddirection1:= "null"
end reset

proc stairs
loop
put "you take a look down the stairs and see that it's flooded. No way are you going down"
put "there anytime soon."
put ""
put "What would you like to do?: "..
get houseaction1
put ""
exit when houseaction1="door" or houseaction1="fireplace" or houseaction1="west"
end loop
end stairs

proc fireplace

end fireplace

proc door
put "you open the door and look around, it's seemingly empty, other than a crumpled up"
put "piece of paper on the ground in the corner. You pick it up, and go back to the main"
put "room to read it."
put "you uncrumple the paper, and notice that it's written in what you think to be red ink"
put "as well as there are some wierd sketches all over it."
put "After some time you realize what they are... It appears to read,"
put "I'm coming for you ",name,"..."
put "The rest is illegible. You stuff the paper into your pocket."
put ""
put "What would you like to do?: "..
get houseaction2
end door

proc stream
loop
put "you see the mouth to a cave to your west on the other side of the river."
put "However there is nothing to the north, or south. But you can always go back"
put "to the main field by heading east."
put ""
put "Where would you like to go?: "..
get streamaction1
put ""
exit when streamaction1="west" or streamaction1="east"
end loop
end stream

proc field
reset
loop
put "you see that you can go east towards a large house on the edge of the clearing"
put "west, towards a small stream,"
put "or south, into a dark dense forest."
put ""
put "Which way would you like to go?: "..
if fielddirection1 = "null" then
get fielddirection1
put ""
exit when fielddirection1="east" or fielddirection1="west" or fielddirection1="south"
end if
end loop
end field

proc house
put "you notice a small fireplace in the corner, some broken stairs down,"
put "a door to the right, and of course the door to the outside"
end house

put "You find yourself in the middle of an open field."
put "You don't recall how you got here."
put "But you have a feeling you're in for an adventure..."
put ""
put "":20,"WELCOME TO..."
put "":22,"ANGORA!"
put ""
put "You will have many options along this game to input your commands."
put "However many of the answers are cardinal directions (ie. East, North etc.)"
put "or simple single word answers such as 'Door'."
put "Keep this in mind to simplify your game."
put ""
put "As you look around, you see a short frail man walking over to you."
put "You call over to him 'Where are we?', but he doesn't answer."
put "He eventually makes his way to you, bends his long stout neck up at you,"
put "and says, 'Your name, young one?'."
put ""
put "Your Name: "..
get name
put ""
put "He nods his head slowly, then turns around."
put "But before you can say anything, he dissapears with a puff of smoke."
put "Trying not to be disheartened you look around."
field
put ""

if fielddirection1="east"
then put "you walk towards the house, and notice that most of the windows are boarded up."
put "But you continue inside anyways."
put "It's very dark inside, but you can make out the shape of someone standing"
put "You start to say something, but it turns around and runs out the door past you."
put "confused you look around for a light source, and come upon a lantern."
put "you quickly light it and take a look around the room."
house
put ""
put "What would you like to do?: "..
get houseaction1
loop
if houseaction1="door" then
put ""
door
else if houseaction1="west" then
put ""
field
else if houseaction1="fireplace" then
put ""
fireplace
else if houseaction1="stairs" then
put ""
stairs
exit when houseaction1="door"
exit when houseaction1="west"
else
put "What would you like to do?: "..
get houseaction1
end if
end if
end if
end if
end loop



if houseaction1="west" then
field
end if
end if

if fielddirection1="south"
then put "You go towards the trees, but its too dark to enter right now."
put "Perhaps you should wait until you have a light source."
put "you go back to the center of the clearing"
put ""
put "Which way do you want to go?: "..
get fielddirection1
end if

if fielddirection1="west"
then put "You slowly walk to the stream, as you admire the beauty of the field"
put "however when you finally make your way over to the crystal-clear water,"
put "you notice that it is too deep to walk through."
put "not wanting to waste your journey over here, you look around for supplies."
stream
put "you also see something shining at the bottom of the water..."
put "however you have no way of reaching it right now."
put ""
put "What would you like to do?: "..
get streamaction1
end if
Aange10




PostPosted: Sat Feb 18, 2012 6:19 pm   Post subject: RE:Resetting variables

To be honest I don't really see the problem.

Try a concept like this


Turing:

% Define some procedures

put Intro Text
get destination
if destination = "fireplace" then
    fireplaceProcedure
etc.
end if


put newIntro text depending on place
get a new choice
repeat
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  [ 7 Posts ]
Jump to:   


Style:  
Search: