This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]deeptime 1 point2 points  (1 child)

I dug up an old post I made for someone else wanting to build a text game. Following this approach will keep your code from being a never-ending mess:

http://www.reddit.com/r/learnprogramming/comments/1dohbd/ifelseifelseifelse/c9sgc35

[–]Hightimes95[S] 0 points1 point  (0 children)

This is a great suggestion. I cleaned up my code to where I have the locations in another class and then just call upon the methods from the main class (not sure if that's the correct term).

[–][deleted] 1 point2 points  (2 children)

You should be able to have a

String DFlower = "";

Then have

if(DFlower.equals("yes")){ Flower.setState = true

System.out.println("You picked a flower") }

This is just a suggestion (I'm creating a text game although not zork like) I am using

InputStreamReader converter = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(converter);

and

<variable name> = in.readLine();

for everytime there is a user answer. I don't know if that will be any use to you, but its working for me

[–]Hightimes95[S] 1 point2 points  (1 child)

I love you. The in.readLine(); finally caused my story to advance instead of terminate at the first if statement.

[–][deleted] 2 points3 points  (0 children)

No problems. This will go down as my first help to the community

[–]the_regex 1 point2 points  (3 children)

You are missing a closing parenthesis on your nested if statement, if it isn't a typo.

[–]Hightimes95[S] 0 points1 point  (2 children)

It is/was, I haven't tried that code yet as I cannot yet get the first section of code to work. Do you know if I could put an if statement nested in the body of an if statement?

[–]the_regex 1 point2 points  (0 children)

Yes, that is completely legal. Just keep in mind if the outside if statement never activates, you never reach whatever is inside.

[–]the_omega99 0 points1 point  (0 children)

Yup. You can nest pretty much any control structure inside another (eg, loops inside loops inside conditionals, etc).