[Solved] Checking if a number if greater than or less than in a for statement?

Discussion in 'Spigot Plugin Development' started by DeadlyBlaze, Jul 13, 2015.

Thread Status:
Not open for further replies.
  1. Hi there, how would I check if a number is greater than or less than? Done this so far ;)
    Code (Text):
    for (int x = max.getBlockX(); x <= min.getBlockX(); x++){
          //Something in here
    }
     
  2. if (number > other || number < other)

    Edit: you said for not if
     
  3. Code (Text):
    for (int i = 0; i < number || i > number; i*+)
     
  4. Thanks, found out why as before I was using >= and <= xD
     
  5. Okay, done that but it's only removing the blocks at two corrners and not the whole area.
    [​IMG]
    Code:
    Code (Text):
                        for (int x = max.getBlockX(); x < min.getBlockX() || x > min.getBlockX(); x++){
                            for (int y = min.getBlockY(); y < max.getBlockY() || y > max.getBlockY(); y++){
                                for (int z = min.getBlockZ(); z < max.getBlockZ() || z > max.getBlockZ(); z++){
                                    max.getWorld().getBlockAt(x, y, z).setType(Material.AIR);
                                }
                            }
                        }
     
  6. Code (Text):

    int minX = Math.min(max.getBlockX(), min.getBlockX());
    int minY = Math.min(max.getBlockY(), min.getBlockY());
    int minZ = Math.min(max.getBlockZ(), min.getBlockZ());
    int maxX = Math.max(max.getBlockX(), min.getBlockX());
    int maxY = Math.max(max.getBlockY(), min.getBlockY());
    int maxZ = Math.max(max.getBlockZ(), min.getBlockZ());

    for (int x = minX; x <= maxX; x++) {
        for (int y = minY; y <= maxY; y++) {
            for (int z = minZ; z <= maxZ; z++) {
                max.getWorld().getBlockAt(x, y, z).setType(Material.AIR);
            }
        }
    }
     
    This does not answer this question, but I can see you are wanting to do something completely different. You mentioned this in another thread already, and like I said there, you have to make sure your values are actual min and max first before anything else. Just because you named the location variables max and min doesnt make them that. ;)
     
    • Like Like x 1
  7. Tried that before and I'm guessing I didn't change the Math.max() to Math.min() for the int maxX/Y/Z it works fine thanks :D

    Sorry about that. #CLUMSEY
     
Thread Status:
Not open for further replies.