I was programming a plugin in Java and I wanted to set 4 different Location
objects. Because in school(C++) they taught us to use [] and I like them (brackets), I decided to do that. Oh boy, I was wrong(or maybe it was just my mistake) I came up with this code:
Location[] pos = new Location[4]; //an array (I guess)
Location loc = e.getBlock().getLocation(); //to get the position of a block
and then I set it in a for loop to iterate trough them like this:
for(int i = 0; i < 4; i++){
pos[i] = loc;
}
But! When I wanted to change any of the pos[x]
variables, all of them changed. Could this be related to pointers or something?
Anyways. I changed my code to do it like this
Location loc = e.getToBlock().getLocation();
Location loc1 = e.getToBlock().getLocation();
Location loc2 = e.getToBlock().getLocation();
Location loc3 = e.getToBlock().getLocation();
This code fortunately works, but how would I go with more variables, what if I wanted something like 200 of them? Or maybe a dinamic "array".
You might be wondering why I said "array" in quotes, but I really have no idea how to call pos[]
other than an array, even tho I know that an Array exists and it's something completely different.