I tried comparing two positions, it didn't work, i checked the coordinates they are the same, my code is: PHP: $pos = new Position($block->getX(), $block->gety(), $block->getZ(), $this->getServer()->getLevelByName("lobby");$pos2 = new Position($block["x"], $block["y"], $block["z"], $this->getServer()->getLevelByName("lobby");if($pos === $pos2){//my code here} It is not working, coordinates are same, i debugged
Hello, Your code is full of errors: $block can not be a object and an array at the same time, you have to choose! Also the Block class is an extend of Position class, so you don't need to create an instantiated object of the Position class... So I give you a code that compares the position of 2 blocks: $block and $block2! PHP: if($block == $block2) // Your code here When using the comparison operator (==), the objects are compared in a simple way: two objects are equal if they have the same attributes and values and they are instances of the same class. Keep me informed.
didn't work, tried this @LCraftPE PHP: $bk = $block; //block from playerinteractevent$xi = $blocks["x"]; $yi = $blocks["y"]; $zi = $blocks["z"]; $pos = new Position($xi,$yi,$zi,$this->getServer()->getLevelByName("lobby")); if($pos == $bk){ //my code }
Re, I explained to you, the comparison operator (==) only works if the two instantiated classes are same. But in your code Position class and Block class are not identical. Here is the real code: PHP: $block2 = new Block($blocks["x"], $blocks["y"], $blocks["z"], $this->getServer()->getLevelByName("lobby"));if($block == $block2) // Your code here If this code doesn't work, could you var_dump $block and give me what you get please. Keep me informed.
Hello, If the comparison operator (==) doesn't work, 2 possibility are proposed to us: The first is that one of the properties of $block has not been defined for $block2 and vice versa. The second is that the coordinates in the $block array are not properly saved. It's up to you to check this out! Keep me informed.