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

Help me update old api enchantments

Discussion in 'Development' started by raelC, Sep 27, 2022.

  1. raelC

    raelC Creeper

    Messages:
    1
    Hello guys, im trying to update my code to api 4.0.0
    but im stucking at getName of Enchantment by ID in new api
    PHP:
    public static $vanilla_enchant = [], $vanilla_options = [];
    public function 
    onEnable(): void
    {
         for (
    $i 0$i <= 36$i++) {
                
    $enchantment EnchantmentIdMap::getInstance()->fromId((int)$i);
                    
    self::$vanilla_enchant[] = $enchantment;
                    
    self::$vanilla_options[] = new MenuOption("⚫ ".$enchantment->getName()." ⚫");
         }
    }
    Error: "Object of class pocketmine\lang\Translatable could not be converted to string"
    Thanks guys
     
  2. BloodyJohnRus

    BloodyJohnRus Silverfish

    Messages:
    19
    GitHub:
    GDSHNIK
    PHP:
    public static $vanilla_enchant = [], $vanilla_options = [];
    public function 
    onEnable(): void
    {
         for (
    $i 0$i <= 36$i++) {
                
    $enchantment EnchantmentIdMap::getInstance()->fromId((int)$i);
                    
    self::$vanilla_enchant[] = $enchantment;
                    
    $name $enchantment->getName();
                    if(
    $name instanceof \pocketmine\lang\Translatable$name $name->getText();
                    
    self::$vanilla_options[] = new MenuOption("⚫ ".$name." ⚫");
         }
    }
    You're welcome.
     
  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.