Solved Variables changing on its own

Discussion in 'Plugin Development' started by NiekZndt, May 6, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    NiekZndt

    Hi everyone,
    Oke in my code I check everyblock in an area for a specific block. I change the targetted block by using the add() function on a location variable. I use a different location variable to reset it but for some reason the location variable that resets also gets changed. My code is a bit messy because I commented some stuff out for debugging.
    Code:
    Location cornerLoc = new Location(Bukkit.getServer().getWorld(args[6]), Double.parseDouble(args[0]) - Double.parseDouble(args[3]), Double.parseDouble(args[1]) - Double.parseDouble(args[4]), Double.parseDouble(args[2]) - Double.parseDouble(args[5]));
                    Location checkLoc = cornerLoc;
                    sender.sendMessage(cornerLoc.toString());
                    for(int x=0; x<=Double.parseDouble(args[3]) * 2 - 1; x++) {
                        for(int y=0; y<=Double.parseDouble(args[4]) * 2 - 1; y++) {
                            for(int z=0; z<=Double.parseDouble(args[5]) * 2 - 1; z++) {
                                checkLoc.add(x, y, z);
                                //if(checkLoc.getBlock().getType() == Material.WHITE_GLAZED_TERRACOTTA)
                                    //Bukkit.getServer().getWorld(args[6]).spawnEntity(checkLoc.add(0, 2, 0), EntityType.ZOMBIE);
                                sender.sendMessage(cornerLoc.toString());
                                //checkLoc = cornerLoc;
    The first three arguments are positions, 3, 4, 5 are scales and the last one is worldname. If I use this and enter 0 for all positions and 1 for all scales it is supposed to say only -1 -1 -1 but instead it says that the value is the same as checkLoc, butin the code the variable cornerLoc never gets changed... I know probably shouldnt use add but I did not find an easy alternative .
     
  2. Offline

    KarimAKL

    @NiekZndt Use Location#clone()#add() instead. The 'checkLoc' variable references the 'cornerLoc' location.
     
    NiekZndt likes this.
  3. Offline

    NiekZndt

    Thank you again for saving my project UwU, it all works fine again and everything looks a lot clearer!
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page