Jump to content

Nested for loops issue on block class


mdf25

Recommended Posts

Hi everyone,

 

First of all thanks to anyone that takes time to help me out :)

 

I've been trying to create a tinted glass block, and a controller and node blocks alongside this so that when you hit the controller block, all the tinted glass blocks change their tint either lighter or darker. The node blocks get placed around the controller (directly above, below, and in each x z direction) which determines the volume of blocks to be checked.

 

I've nearly got to the end of the process, sooooo close now, but I've found out through some debugging that I am having an issue with 3 nested for loops (getting x, y, and z values which were determined from another method). The variables I need are also stored in the constructor which I assume may be causing the issues.

 

Here is my code - I've commented where the issues are near the bottom

http://pastebin.com/XYP1D5Wn

 

NB: There's an @Override on one of my methods in this class because it extends that from my other block class so I don't think this is causing any issues?

 

My first loop (for a = lowX; a <= highX; a++) works fine but the b (and c) loops are not getting initialised.

 

Some things I tried were setting variable names outside the loop like this:

 

public boolean changeBlocksInArea(EntityPlayer player, World world, int lowX, int highX, int lowY, int highY, int lowZ, int highZ, String blockName, int flag){
    System.out.println("Loop a started");
    int lx = lowX;
    int hx = highX;
    for(a = lx; a <= hx; a++){
        System.out.println("Loop b started");
        int ly = lowY;
        int hy = highY;
        for(b = ly; b<= hy; b++){
            System.out.println("Loop c started");
            int lz = lowZ;
            int hz = highZ;
            for(c = lz; c<= hz; c++){

                 //Do stuff

            }
        }
    }
}

 

However this also gave the same result...

 

Any ideas?

Link to comment
Share on other sites

The code looks correct to me.  So if it is only executing the outer loop that means the condition for the b<=highY must be false right away.  Are you sure lowY is less than highY?  Is it possible that your highY has a negative value?

 

Derp!

 

For some reason my highY was less than the lowY so they must be getting swapped around in the previous function... More devugging! :D

 

Thanks for the help :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.