Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Boolean trouble, no idea whats wrong.

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Boolean trouble, no idea whats wrong.

    When i run the following code it is rendering the first xyz coords from the text file without a right side, and often other booleans get messed up.

    public static void readBlockXYZtxt(){
    		File file = new File("blockXYZ.txt");
     
    		if (!file.exists()){
     
    			Writer output;
    			try{
    				output = new BufferedWriter(new FileWriter("blockXYZ.txt", true));
    				//output.append("hello");
    				output.close();
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		} else {
    			try{
    				BufferedReader br = new BufferedReader(new FileReader("blockXYZ.txt"));
     
    				String allText;
    				String[] blockXYZ;
    				String[] xyzINDVblock;
    				String block;
     
    				//String blockXstr;
    				//String blockYstr;
    				//String blockZstr;
     
    				int blockX;
    				int blockY;
    				int blockZ;
     
    				while ((allText = br.readLine()) != null){
    					blockXYZ = allText.split("N");
    					int BlockAmount = blockXYZ.length;
    					//
     
     
    					amountBlocks = amountBlocks + BlockAmount;
     
    					for (int i=0;i<BlockAmount;){
    						boolean renderFront = true;
    						boolean renderBack = true;
    						boolean renderLeft = true;
    						boolean renderRight = true;
    						boolean renderTop = true;
    						boolean renderBottom = true;
    						block = blockXYZ[i];
    						xyzINDVblock = block.split("-");
     
    						System.out.println(BlockAmount);
     
    						blockX = Integer.parseInt(xyzINDVblock[0]);
    						blockY = Integer.parseInt(xyzINDVblock[1]);
    						blockZ = Integer.parseInt(xyzINDVblock[2]);
     
    						if (allText.contains(blockX+"-"+blockY+"-"+(blockZ-1)+"N")){
     
    							renderFront = false;
    							System.out.println("renderFront "+renderFront+""+i);
    						}
     
    						if (allText.contains(blockX+"-"+blockY+"-"+(blockZ+1)+"N")){
    							renderBack = false;
    							System.out.println("renderBack == "+renderBack+""+i);
    						}
     
    						if (allText.contains((blockX+1)+"-"+blockY+"-"+blockZ+"N")){//
     
    							renderLeft = false;
    							System.out.println("renderLeft "+renderLeft+""+i);
    						}
     
    						if (allText.contains((blockX-1)+"-"+blockY+"-"+blockZ+"N")){
    							renderRight = false;
    							System.out.println((blockX-1)+"-"+blockY+"-"+blockZ+"N");
    							System.out.println("renderRight == "+renderRight+""+i);
    						}
     
    						if (allText.contains(blockX+"-"+(blockY+1)+"-"+blockZ+"N")){//
     
    							renderTop = false;
    							System.out.println("renderTop "+renderTop+""+i);
    						}
     
    						if (allText.contains(blockX+"-"+(blockY-1)+"-"+blockZ+"N")){//
     
    							renderBottom = false;
    							System.out.println("renderBottom "+renderBottom+""+i);
    						}
    						cubeVertex(blockX, blockY, blockZ, renderFront, renderBack, renderLeft, renderRight, renderTop, renderBottom);
     
     
    						/*if (blockY > 0){
    							for (int r=0;r<blockY;){
    								cubeVertex(blockX, r, blockZ, renderFront, renderBack);
    								r++;
    							}
    						}*/
    						i++;
    					}
     
    					//System.out.println(blockXstr);//blockXYZ = x, y, z
    					//System.out.println(allText);
    					//System.out.println(BlockAmount);
    					//System.out.println(part3);
     
    				}
    	            br.close();
    				} catch (IOException e){
    					System.out.println("File Read Error");
    				}
     
    		}
     
    	}


    Text file:
    2-0-2N3-0-2N4-0-2N4-1-2N5-0-2N5-1-2N6-0-2N7-0-2N7-1-2N8-0-2N8-1-2N9-0-2N9-1-2N10-0-2N10-1-2N11-0-2N11-1-2N12-0-2N12-1-2N2-0-3N3-0-3N3-1-3N4-0-3N5-0-3N6-0-3N7-0-3N7-1-3N8-0-3N9-0-3N9-1-3N10-0-3N11-0-3N12-0-3N2-0-4N2-1-4N3-0-4N4-0-4N4-1-4N5-0-4N6-0-4N7-0-4N8-0-4N8-1-4N9-0-4N10-0-4N10-1-4N11-0-4N11-1-4N12-0-4N2-0-5N2-1-5N3-0-5N3-1-5N4-0-5N4-1-5N5-0-5N6-0-5N7-0-5N8-0-5N8-1-5N9-0-5N10-0-5N11-0-5N11-1-5N12-0-5N12-1-5N2-0-6N2-1-6N3-0-6N3-1-6N4-0-6N4-1-6N5-0-6N6-0-6N6-1-6N7-0-6N7-1-6N8-0-6N9-0-6N10-0-6N10-1-6N11-0-6N12-0-6N12-1-6N2-0-7N3-0-7N3-1-7N4-0-7N4-1-7N5-0-7N6-0-7N7-0-7N7-1-7N8-0-7N8-1-7N9-0-7N9-1-7N10-0-7N10-1-7N11-0-7N12-0-7N12-1-7N2-0-8N3-0-8N3-1-8N4-0-8N5-0-8N5-1-8N6-0-8N6-1-8N7-0-8N7-1-8N8-0-8N8-1-8N9-0-8N9-1-8N10-0-8N11-0-8N11-1-8N12-0-8N2-0-9N2-1-9N3-0-9N3-1-9N4-0-9N4-1-9N5-0-9N5-1-9N6-0-9N6-1-9N7-0-9N8-0-9N9-0-9N10-0-9N11-0-9N11-1-9N12-0-9N12-1-9N2-0-10N3-0-10N4-0-10N4-1-10N5-0-10N6-0-10N6-1-10N7-0-10N8-0-10N8-1-10N9-0-10N10-0-10N10-1-10N11-0-10N11-1-10N12-0-10N12-1-10N2-0-11N2-1-11N3-0-11N3-1-11N4-0-11N4-1-11N5-0-11N6-0-11N6-1-11N7-0-11N7-1-11N8-0-11N9-0-11N9-1-11N10-0-11N11-0-11N12-0-11N


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,530
    My Mood
    Mellow
    Thanks
    157
    Thanked 615 Times in 602 Posts

    Default Re: Boolean trouble, no idea whats wrong.

    Huh? Can you tell us what the code is supposed to do and describe to us what it's not doing? What do you mean by "rendering?" If it's a console-based app, post a sample run and describe what's wrong with it. And (if it matters) what is the significance of the entries in the text file? Are there any compiler or runtime errors? If so, post those.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    Cekeh (September 20th, 2013)

  4. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Boolean trouble, no idea whats wrong.

    im using it to generate cubes at the coords in the text file with LWJGL, but when this code runs it puts x, y, z into their own variables then , for instance, the first variable in the text file is 2-0-2, then it searches the text file for the block (or coord) for example to the right, but its searching the file for 1-0-2 taking away one on the x AND ITS RETURNING TRUE for some off reason.

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,530
    My Mood
    Mellow
    Thanks
    157
    Thanked 615 Times in 602 Posts

    Default Re: Boolean trouble, no idea whats wrong.

    One of the keys to not writing a mass of code that doesn't work is to write it in small bits, testing as you go. Then, when you find yourself with broken code, you know to start with the last bit of code that wasn't broken and to fix the recent changes.

    The code posted below is your code that I condensed into the part that I think does what you think it doesn't, and I didn't make any significant changes other than changing the file name. You're either not understanding the results of your own code or not using them properly. And you're not very good at explaining what you're trying to do and/or what's wrong. Work on that. Oh, and comment your code.
    // reads the file and parses it into x-y-z coordinates at each 'N'
    public static void readBlockXYZtxt()
    {
        File file = new File("./files/blockXYZ.txt");
     
        try
        {
            // opens the file for reading
            BufferedReader br = new BufferedReader(new FileReader( file ));
     
            // a variable to store each line and an array to store the line
            // after it's split at each 'N'
            String allText;
            String[] blockXYZ = null;
     
            // a counter to index the array of coordinates when printing
            int i = 0;
     
            // read the file and store the x-y-z coords in an array at each 'N'
            while ((allText = br.readLine()) != null)
            {
                blockXYZ = allText.split("N");
            }
     
            // closes the BufferedReader
            br.close();
     
            // print the resulting array of x-y-z coordinates
            for ( String xyz : blockXYZ )
            {
                System.out.println( "blockXYZ[i++] = " + xyz );
            }
        }
        catch ( Exception e )
        {
            // TODO don't leave this empty
        }
     
    }

  6. The Following User Says Thank You to GregBrannon For This Useful Post:

    Cekeh (September 20th, 2013)

  7. #5
    Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Default Re: Boolean trouble, no idea whats wrong.

    Are you possibly misunderstanding what the code is suppose to be doing? As you mentioned the code is checking to make sure the space next to it is empty. If it's got something next to it then it does not render that side. In your example of the error I think you are simply misunderstanding what is happening. The first coordinate still remains the same 2-0-2. Next your if statement checks at (2-1)-0-2 which there is nothing else at that spot so it tells it that it is ok to render that side.

    Small example of what is happening
    // Declare and initialize variables
    int x = 5;
    int y = 10;
     
    // Checks 5 + 3 < 10
    if (x + 3 < y){
       // Show that the value for x has not changed
       System.out.printf("This text shows up because (%d < 10) You can see that variables remain unchanged x = %d y = %d", x + 3, x, y);
    }

    Simply because you do a check where you add to the value or subtract from the value it does not mean it will change the variables value. You would have to assign it a new value for it to change. So in your example the fact remains that the value it is checking is (1-0-2) but the value of the coordinates still remains (2-0-2) Other portions of your code also check (3-0-2, 2-(-1)-2, 2-1-2...etc).

    Now if you're expecting your code to do something different then it will most likely be an error in logic. If you are still having errors post a more descriptive reply about what you expect it to do and what the result is ending up with.

  8. The Following User Says Thank You to Ubiquitous For This Useful Post:

    Cekeh (September 20th, 2013)

Similar Threads

  1. Boolean value prints out the wrong one.
    By Shzylo in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 3rd, 2013, 08:11 PM
  2. Help! have no idea what's wrong with my code..
    By Zaki in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 17th, 2012, 09:22 PM
  3. Boolean and String Trouble...
    By Souljahgirl101 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 3rd, 2012, 08:17 PM
  4. Replies: 2
    Last Post: September 2nd, 2012, 02:06 PM
  5. [SOLVED] What's wrong with this boolean?
    By bgroenks96 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: June 8th, 2011, 06:41 PM

Tags for this Thread