1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Object of class pocketmine\item\DiamondPickaxe could not be converted to int in phar

Discussion in 'Development' started by Fair, Nov 29, 2017.

  1. Fair

    Fair Creeper

    Messages:
    4
    GitHub:
    FairSYS
    [Server] Notice: Object of class pocketmine\item\DiamondPickaxe could not be converted to int in phar:///storage/emulated/0/PocketMine/plugins/PE_v1.0.0.phar/src/Explosive/Explosive.php on line 58
    [Server] [18:03:10] [Server thread/INFO]: VineyYT left the game
    [Server] [18:03:10] [Server thread/INFO]: VineyYT[/10.0.0.102:41373] logged out due to timeout
    [Server] [18:03:10] [Server thread/INFO]: There are 0/20 players online:
    [Server] [18:03:10] [Server thread/INFO]:
     
  2. Fair

    Fair Creeper

    Messages:
    4
    GitHub:
    FairSYS
    public function onBreak(BlockBreakEvent $ev){
    if($ev->getItem() == 278 && $ev->getItem()->getCustomName() == "Explosive"){ //line 58
    $explosion = new Explosion($ev->getPlayer()->getPosition(), 1.5, $this);
    $explosion->explodeB();
     
  3. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    You're comparing an item object to an integer, which makes php want to convert the item object to a number. (Spoiler: It fails doing so)

    So instead of trying to do this
    PHP:
    $ev->getItem() == 278 // this isn't good
    try to use that:
    PHP:
    $ev->getItem()->getId() === 278 // this is better
    (Yes, you can also just use ==. It's just that I prefer ===)
     
    Muqsit and Karanpatel567 like this.
  4. Fair

    Fair Creeper

    Messages:
    4
    GitHub:
    FairSYS
     
  5. Fair

    Fair Creeper

    Messages:
    4
    GitHub:
    FairSYS
    Oh,thank you
     
  6. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    === means 'identical to'
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.