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

getItem() error.

Discussion in 'Development' started by InspectorGadget, Dec 21, 2016.

  1. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi, I have been getting this error on this particular line. Anyone know why? I have used the correct "use" functions but still throws up this error.
    PHP:
            // Item gather
            
    $ds Item::getItem(27601); // D Sword - line 117
            
    $h Item::getItem(31001); // D Helmet
            
    $c Item::getItem(31101); // D Chestpiece
            
    $l Item::getItem(31201); // D Legging
            
    $b Item::getItem(31301); // D Boot
            // close Item gather
    PHP:
    Error:
    21.12 04:49:06 [ServerServer thread/CRITICAL Unhandled exception executing command 'kit infinity' in kitCall to undefined method pocketmine\item\Item::getItem()
    Thanks :)
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    I think it is Item::get(stuff) instead of Item::getItem(stuff)
     
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    its item Item::get(0,0,0) or item::get(Item::AIR,0,1)
     
  4. Wii54

    Wii54 Silverfish

    Messages:
    16
    GitHub:
    wii54
    why not just new Item(0,0,0)?
     
  5. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I'll try that.
     
  6. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Because it's considered bad practice.
     
    SOFe, 0x15f and Muqsit like this.
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You cannot use Item::getItem() anyways (it doesn't exist in Item.php and extensions, and is a non-static function in BaseInventory). It's better to read the source and understand, than predicting.
     
    SOFe likes this.
  8. Wii54

    Wii54 Silverfish

    Messages:
    16
    GitHub:
    wii54
    It does work
     
  9. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I agree, I couldn't find it at that time. That's why, I asked here.
     
  10. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    Yes it works, but as Jack said it's bad practice; same as Server::getInstance(); it's bad practice. Just because something works doesn't mean that it should be done that way.
     
    Jack Noordhuis likes this.
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Why do you think only BaseInventory has getItem()?
     
  12. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    It sometimes doesn't work, because Item::get() returns an item with the proper class while new Item() always returns objects in Item type instead of using the proper subclass. This may result in some items displaying wrong names, or not behaving in the special actions as they should (e.g. when they are used on a block).
     
    Muqsit and 0x15f like this.
  13. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Well...I couldn't think of a proper way of expressing that. :shoghi:
     
  14. Wii54

    Wii54 Silverfish

    Messages:
    16
    GitHub:
    wii54
    Oh I did not know about that
     
  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.