Results 1 to 6 of 6
  1. #1
    chaucer345 is offline Member
    Join Date
    Dec 2012
    Posts
    39
    Rep Power
    0

    Default The Case of the Mysteriously Modified Boolean, (how do I fix this code?)

    Hello all, I seem to have fallen onto some stumbling blocks in a text adventure program I'm trying to design. I know there are probably lots of problems with the code below, but taking things one at a time I was hoping to figure out why it's impossible to move from room 1 to room 2 and call the appropriate branches of code. Here's how it should work. The main GUI program changes the value of input when the player requests it and calls a method based on the scene of the game the player is in. In this example, scene 3 is what is called. When the player enters 2 after just entering room 1 what should happen is:
    input= 2
    room = 1
    justEntered = true
    moved = true

    And the player should be prompted to hit 1 to continue on to the next room. From some various tests I've run and how the program behaves, this part works fine. However, when the user enters 1, what seems to happen is that the code branch that takes the user west is called, instead of the code branch which should be called when justEntered is true. Thus, somehow justEntered is modified from true to false before the method is called. I honestly have no idea why this is happening.

    Below is the code for the called method. If anyone can give me advice as to what's going on, I would be extremely grateful. (Note, I know the code block below is intimidatingly large, but don't worry, most of the volume is from String Literals).


    Java Code:
    private String scene3() {
    		String newText = "";
    		if (room == 1) {
    			if (justEntered) {
    				newText = newText + location();
    				moved = false;
    				System.out.println("Room 1 reached");
    			}
    			// NOTE: The dialogue tree needs to change based on how the players
    			// have interacted with Wind
    
    			if (isTalking == true && justEntered != true && input == 1
    					&& internalTime == 1) {
    				newText = newText
    						+ "\"I'm a... a medic. I'm one of the more experienced ones\n"
    						+ "among the earth pony unions. I teach where I can, patch people up\n"
    						+ "when I can, and I'm here right now because Blueblood's an old\n"
    						+ "friend of mine and thought someone with medical training should be helping\n"
    						+ "Ura. She's briliant, but she needs some help calibrating her healing potions."
    						+ "to pony physiology\"\n";
    			}
    			if (isTalking == true && justEntered != true && input == 2
    					&& internalTime == 1 && windQuest == false) {
    				newText = newText
    						+ "Wind looks a little pale. \"Uh, nothing major. Just forget about it.\"\n"
    						+ "She looks genuinely shaken up. She reaches into her vest pocket and pulls out\n"
    						+ "a tiny saddle flask. She takes a sip of it and puts it back. You raise an eyebrow.\n"
    						+ "1) What was that?\n" + "2) Say nothing\n";
    				internalTime++;
    				largestChoice = 2;
    			}
    			if (isTalking == true && justEntered != true && input == 2
    					&& internalTime == 1 && windQuest == true)
    				newText = newText
    						+ "Wind sighs. \"Can we please move on to the next topic.\"\n";
    			if (isTalking == true && justEntered != true && input == 2
    					&& internalTime == 2) {
    				newText = newText
    						+ "The mare sighs and looks back up at you. \"So, was there anything else?\"\n";
    				internalTime = 1;
    				windQuest = true;
    			}
    			if (isTalking == true && justEntered != true && input == 1
    					&& internalTime == 2) {
    				newText = newText
    						+ "\"It's nothing I just... I have a condition which puts me\n"
    						+ "in a lot of pain sometimes. So... I medicate.\"\n"
    						+ "You sniff the air. You know exactly what sort of medication that is.\n"
    						+ "1) You're a drunk!\n"
    						+ "2) Maybe you should give me that flask.\n"
    						+ "3) Say nothing\n";
    				largestChoice = 3;
    				internalTime++;
    			}
    			if (isTalking == true && justEntered != true && input == 1
    					&& internalTime == 3) {
    				newText = newText
    						+ "\"What?\" Wind narrows her eyes. \"Listen pal, I'm\n"
    						+ "not lying. You think I like living in a place with no aspirin?\n"
    						+ "You think I like the taste of moldy hay vodka? I live my life \n"
    						+ "in bucking misery, all because I...\"\n"
    						+ "She stops, she takes a deep breath.\n"
    						+ "\"We're changing the subject.\"\n";
    				internalTime = 1;
    				windQuest = true;
    				windOpinion--;
    			}
    			if (isTalking == true && justEntered != true && input == 2
    					&& internalTime == 3) {
    				newText = newText
    						+ "\"I... I...\" She pauses. She takes a deep breath.\n"
    						+ "\"I have been medicated enough today. I am not in pain. I \n"
    						+ "do not need more medication.\" She pulls out the flask and shakilly\n"
    						+ "holds it out to you. You take it from her.\n"
    						+ "\"Thank you\" She says.\n"
    						+ "There is a small pause.\n"
    						+ "\"So,\" She says finally, \"Anything else you wanted to ask?\"\n";
    				flask = true;
    				windQuest = true;
    				windOpinion++;
    				internalTime = 1;
    			}
    			if (isTalking == true && justEntered != true && input == 3
    					&& internalTime == 3) {
    				newText = newText
    						+ "There is an awkward, extended silence."
    						+ "\"So,\" Wind says finally, \"Anything else you wanted to ask?\"\n";
    				windQuest = true;
    				internalTime = 1;
    			}
    			if (isTalking == true && justEntered != true && input == 3
    					&& internalTime == 1) {
    				newText = newText
    						+ "\"There's a lot to tell. We're technically legal,\n"
    						+ "we even get donations sometimes. Our union isn't really about confronting\n"
    						+ "the non-earth pony populous directly... usually I get Blueblood to do\n"
    						+ "that part. We're really mostly a training organization. We \n"
    						+ "travel around teaching first aid and hygine as much as we can. We try\n"
    						+ "to train ponies up to be half decent medical providers if they've got\n"
    						+ "enough drive. Those cases are few and far between though. There's a reason\n"
    						+ "why the Cloudsdale medical academy takes so long to get through.\"\n"
    						+ "She gets a little smile on her face. \"I like to think we've saved some\n"
    						+ "lives.\"\n";
    			}
    			if (isTalking == true && justEntered != true && input == 4
    					&& internalTime == 1) {
    				newText = newText
    						+ "\"Well I've known Blueblood the longest. He can get a bit\n"
    						+ "corny at times, but I think if half the ponies in Equestria had his heart\n"
    						+ "this place would be chock full of sunshine and rainbows\n"
    						+ "Ura's a good kid. She's brilliant and she tries to keep a smile on her\n"
    						+ "face even when things really suck, which for someone like her, they often\n"
    						+ "do.\n"
    						+ "Hard Knock...\n"
    						+ "She sighs. \n"
    						+ "He's lived a tough life, and he's genuinely trying to help. I respect\n"
    						+ "him for that.\"\n";
    				if (race != 3) {
    					newText = newText
    							+ "\"But I would respect him a lot more if he hadn't\n"
    							+ "given you that bruise.\"\n";
    				}
    
    			}
    			if (isTalking == true && justEntered != true && input == 5
    					&& internalTime == 1) {
    				newText = newText + "\"Okay, see you later.\"\n";
    				isTalking = false;
    			}
    			if (isTalking) {
    				if (internalTime == 1) {
    					newText = newText
    							+ "1) What do you do here?\n"
    							+ "2) Seriously, what was that thing with your hoof earlier?\n"
    							+ "3) Can you tell me more about the stitchers?\n"
    							+ "4) What do you think of the other people down here?\n"
    							+ "5) I should go.\n";
    					largestChoice = 5;
    				}
    			}
    			//options for if the player is not talking to Wind, the boolean moved tracks whether the player has moved
    			if (isTalking != true && justEntered != true && input == 2) {
    				newText = newText + "You head North. Enter 1 to enter.\n";
    				room = 2;
    				justEntered = true;
    				moved = true;
    				largestChoice = 1;
    				System.out.println(justEntered);
    			}
    			if (isTalking != true && justEntered != true && input == 1) {
    				newText = newText + "You head West. Enter 1 to enter,\n";
    				room = 4;
    				justEntered = true;
    				moved = true;
    				largestChoice = 1;
    				System.out.println(justEntered);
    			}
    			if (isTalking != true && justEntered != true && input == 3) {
    				newText = newText
    						+ "Wind turns to you. \"Yes?\"\n"
    						+ "1) What do you do here?\n"
    						+ "2) Seriously, what was that thing with your hoof earlier?\n"
    						+ "3) Can you tell me more about the Stitchers?\n"
    						+ "4) What do you think of the other people down here?\n"
    						+ "5) I should go.\n";
    				isTalking = true;
    				largestChoice = 5;
    			}
    			if (isTalking != true && justEntered != true && input == 4) {
    				newText = newText
    						+ "You look at the medicine cabinet and jiggle the lock.\n"
    						+ "Wind raises an eyebrow. \"What are you doing?\"\n"
    						+ "You back off sheepishly.\n";
    			}
    			if (isTalking != true && justEntered != true && input == 5) {
    				newText = newText
    						+ "You go up to the basin and splash water on your face.\n";
    				if (health < 5) {
    					newText = newText + "You feel a little rejuvinated.\n";
    					health++;
    				}
    			}
    			if (isTalking != true && justEntered != true && input == 6) {
    				newText = newText + breatheDeep();
    				justEntered = true;
    
    			}
    			
    			if (isTalking != true && moved != true) {
    				newText = newText + roomOptions();
    			}
    			justEntered = false;
    		}
    		//ROOM 2
    		else if (room == 2) {
    			if (justEntered) {
    				newText = newText + location();
    				moved = false;
    			}
    			// NOTE: The dialogue tree needs to change based on how the players
    			// have interacted with Hard Knock
    
    			if (isTalking == true && justEntered != true && input == 1
    					&& internalTime == 1) {
    				newText = newText
    						+ "\"I'm a soldier. I fought for Seasons for a while in the\n"
    						+ "earth pony corps\n";
    				if (race == 3) {
    					newText = newText + "But you know what that's like...\n";
    				}
    				newText = newText
    						+ "I\'m here with the Coalition. I\'m our \n"
    						+ "main line of defense against all Season's might...\"\n"
    						+ "He shakes his head. \"It's not an easy job.\" "
    						+ "There is a pause. \"I also lift heavy things.\"\n";
    			}
    			if (isTalking == true && justEntered != true && input == 2
    					&& internalTime == 1 && hardKnockQuest == false) {
    				if (race != 3) {
    					newText = newText + "\"Let's see, you're one of the";
    					if (race == 1) {
    						newText = newText + "unicorns ";
    					}
    					if (race == 2) {
    						newText = newText + "pegasi ";
    					}
    					newText = newText
    							+ "who's spent their"
    							+ "lives spitting on magicless ponies like me, you were part of a group explicitly\n"
    							+ "tasked with quashing refugees, and there's a good chance that you're\n"
    							+ "a plant by Queen Seasons sent here to find out the location of this base\n"
    							+ "and all our others.\"\n"
    							+ "1) I know those stretches, you were a solider yourself.\n"
    							+ "2) Say nothing.\n";
    				} else {
    					newText = newText
    							+ "He sighs \"I'd like to trust you, I really would, but I \n"
    							+ "just can't risk it. Everyone here is relying on me to keep them safe,\n"
    							+ "and I can't just ignore the fact that you might be a spy or worse.\n"
    							+ "You did good out there, but you were a soldier for Seasons and you might\n"
    							+ "still be.\n"
    							+ "1) I know those stretches, you were a solider yourself.\n"
    							+ "2) Say nothing.\n";
    				}
    				internalTime++;
    				largestChoice = 2;
    			}
    			if (isTalking == true && justEntered != true && input == 2
    					&& internalTime == 1 && hardKnockQuest == true)
    				newText = newText + "\"We've had that conversation.\"\n";
    			if (isTalking == true && justEntered != true && input == 2
    					&& internalTime == 2) {
    				newText = newText
    						+ "Hard Knock nods. \"That about sums it up\"\n";
    				internalTime = 1;
    				hardKnockQuest = true;
    			}
    			// this makes 1 or 2 a pseudo choice.
    			if (isTalking == true && justEntered != true && input == 1
    					&& internalTime == 2) {
    				newText = newText
    						+ "He nods \"I'm a soldier. I fought for Seasons for a while in the\n"
    						+ "earth pony corps\n";
    				if (race == 3) {
    					newText = newText + "But you know what that's like...\n";
    				}
    				newText = newText
    						+ "I managed to live through it. Then I tried to join up with\n"
    						+ "The Family for a while, but they didn't like my faith, or... a few other things\n"
    						+ "about me so they kicked me out. So now I work for Blueblood.\" He sighs\n"
    						+ "\"I guess it's the only place for a freak like me.\"\n"
    						+ "For a moment he looks utterly miserable. It seems like there's something he's not telling you.\n"
    						+ "1) You don't seem too freakish to me.\n"
    						+ "2) What are you hiding?\n" + "3) Say nothing\n";
    				largestChoice = 3;
    				internalTime++;
    			}
    			if (isTalking == true && justEntered != true && input == 1
    					&& internalTime == 3) {
    				newText = newText
    						+ "Hard Knock gives you a little smile. For a moment it looks\n"
    						+ "like he's blushing. \"Thanks. Do me a favor and don't be an evil scheming \n"
    						+ "spy okay?\" He turns his head to the side for a moment and idly scratches it \n"
    						+ "with a hoof. \"So... Anything else?\"\n";
    				internalTime = 1;
    				hardKnockQuest = true;
    				hardKnockOpinion++;
    			}
    			if (isTalking == true && justEntered != true && input == 2
    					&& internalTime == 3) {
    				newText = newText
    						+ "Hard Knock narrows his eyes \"I'm not hiding anything. I...\"\n"
    						+ "He strains for a moment. Finally he chokes out \"I-like-stallions.\"\n"
    						+ "He lets out a breath and glares at you. \"There, are you bucking happy?\n"
    						+ "What else did you want to know?\"\n";
    				hardKnockQuest = true;
    				hardKnockOpinion--;
    				internalTime = 1;
    			}
    			if (isTalking == true && justEntered != true && input == 3
    					&& internalTime == 3) {
    				newText = newText
    						+ "Heart shakes himself for a moment and\n"
    						+ "his expression returns to normal. \"Anything else you wanted to ask?\"\n";
    				windQuest = true;
    				internalTime = 1;
    			}
    			if (isTalking == true && justEntered != true && input == 3
    					&& internalTime == 1) {
    				newText = newText
    						+ "Hard Knock looks unusually sheepish. \"I... I keep the"
    						+ "old faith. You know, the one from before Seasons? I know most"
    						+ "ponies think it's just a fairy tale, but I have faith that the "
    						+ "old gods are still out there. Maybe, just maybe if I try and bring some"
    						+ "light into this crazy world, then Loyalty, Honesty, Generosity, Kindness, "
    						+ "Laughter and the Unnamed Binder will awaken from their long slumber"
    						+ "and restore harmony to the world.\""
    						+ "Hard Knock lets out a breath. \"I guess that makes me a little crazy, but"
    						+ "it just feels right.\"";
    			}
    			if (isTalking == true && justEntered != true && input == 4
    					&& internalTime == 1) {
    				newText = newText
    						+ "\"Well Blueblood's a bit annoying sometimes, but he's a"
    						+ "good pony and he and I... well he took me in when I got thrown out"
    						+ "of Empire's union. We... We share some stuff and it means a lot to"
    						+ "me that he doesn't think I'm a freak for my faith or, well, anything else."
    						+ "Ura I don't know much about. She's really smart and nice, but"
    						+ "I worry she always feels like a fish out of water. I wish there"
    						+ "was something I could do to help her out. I worry she's a little"
    						+ "scared of me."
    						+ "And Wind? We go way back. I used to be drinking buddies with her"
    						+ "before she quit. She's a dab hand at cards, and she's patched me up"
    						+ "more times than I can count.";
    			}
    			if (isTalking == true && justEntered != true && input == 5
    					&& internalTime == 1) {
    				newText = newText
    						+ "Hard Knock nods and goes back to his exercises.\n";
    				isTalking = false;
    			}
    			if (isTalking) {
    				if (internalTime == 1) {
    					newText = newText
    							+ "Hard Knock raises an eyebrow. \"What?\"\n"
    							+ "1) What do you do here?\n"
    							+ "2) What's your problem with me?\n"
    							+ "3) You mentioned the old gods?\n"
    							+ "4) What do you think of the other people down here?\n"
    							+ "5) I should go.\n";
    					largestChoice = 5;
    				}
    			}
    			if (isTalking != true && justEntered != true && input == 2) {
    				newText = newText + "You head South. Enter 1 to enter.\n ";
    				room = 1;
    				justEntered = true;
    				moved = true;
    				largestChoice = 1;
    				System.out.println(justEntered);
    			}
    			if (isTalking != true && justEntered != true && input == 1) {
    				newText = newText + "You head West. Enter 1 to enter,\n";
    				room = 3;
    				justEntered = true;
    				moved = true;
    				largestChoice = 1;
    				System.out.println(justEntered);
    			}
    			if (isTalking != true && justEntered != true && input == 3) {
    				newText = newText
    						+ "Hard Knock raises an eyebrow. \"What?\"\n"
    						+ "1) What do you do here?\n"
    						+ "2) What's you're problem with me?\n"
    						+ "3) You mentioned the old gods?\n"
    						+ "4) What do you think of the other people down here?\n"
    						+ "5) I should go.\n";
    				isTalking = true;
    				largestChoice = 5;
    			}
    			if (isTalking != true && justEntered != true && input == 4) {
    				newText = newText
    						+ "You eye the weapon's cabinet. Through its\n"
    						+ "heavy mesh you can make out a large selection of implements\n"
    						+ "of destruction. You take a step towards it.\n"
    						+ "Suddenly, Hard Knock appears behind you.\n"
    						+ "\"Don't even think about it.\"\n"
    						+ "You take a step back.\n";
    			}
    			if (isTalking != true && justEntered != true && input == 5) {
    				newText = newText
    						+ "You go up to the bags and give them a kick.\n";
    				if (race == 3) {
    					newText = newText
    							+ "Your prosthesis complains at the abuse, but there's\n"
    							+ "a clever little shock system built into it that holds\n"
    							+ "it together.\n";
    				}
    				if (race != 3) {
    					newText = newText
    							+ "You feel a shock up your legs as you make a strong impact.\n";
    				}
    				newText = newText
    						+ "Hard Knock ignores you. He appears lost in his own little world.\n";
    			}
    			if (isTalking != true && justEntered != true && input == 6) {
    				newText = newText + breatheDeep();
    				justEntered = true;
    
    			}
    			justEntered = false;
    			if (isTalking != true && moved != true) {
    				newText = newText + roomOptions();
    			}
    			
    		} else if (room == 3) {
    			/*
    			 * TODO code for what happens in the lab
    			 */
    		} else if (room == 4) {
    			/*
    			 * TODO code for what happens in the kitchen
    			 */
    		}
    		return newText;
    	}

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    5

    Default Re: The Case of the Mysteriously Modified Boolean, (how do I fix this code?)

    Hi chaucer345,

    Your code is a little difficult to read, I got lost at the if statement .
    But, if I understand your problem correctly, if the player is in room 1 then justEntered is being reset on line 192.

    Regards.

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: The Case of the Mysteriously Modified Boolean, (how do I fix this code?)

    Get in the habit of using standard Java naming conventions!

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: The Case of the Mysteriously Modified Boolean, (how do I fix this code?)

    Get in the habit of using standard Java naming conventions!

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,732
    Blog Entries
    7
    Rep Power
    21

    Default Re: The Case of the Mysteriously Modified Boolean, (how do I fix this code?)

    The code itself already is a text adventure; with twisty little passages all alike; please fix it, I can't wade through it (and I tried).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default Re: The Case of the Mysteriously Modified Boolean, (how do I fix this code?)

    Debug debug debug.
    (And refactor).

    Stick debug statements in there (ie System.out.println()) or use a debugger to follow the flow through that monster.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 08-07-2012, 08:21 PM
  2. Replies: 3
    Last Post: 09-13-2011, 01:01 AM
  3. my simple boolean code keeps saying true
    By shazakala in forum New To Java
    Replies: 8
    Last Post: 03-27-2011, 11:30 AM
  4. Modified Pixels
    By monkey04 in forum Java 2D
    Replies: 1
    Last Post: 03-12-2009, 09:15 AM
  5. JSP Last Modified Date
    By thagentleman in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-18-2008, 05:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •