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

error in new api

Discussion in 'Development' started by abdullah, Jun 21, 2018.

  1. abdullah

    abdullah Spider

    Messages:
    14
    GitHub:
    x3boodx
    hello pmmp community ,

    in old api [3.0.0alpha12] if I do that :
    PHP:
    <?php

    namespace test;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase
    {

        public function 
    onEnable()
        {

            
    $this->ANYTHING "blabla";

        }

        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args): bool
        
    {

            switch (
    $cmd->getName())
            {

                case 
    'a':
                    
    $sender->sendMessage("$this->ANYTHING");
                    break;

            }
        }
    }

    the message will be send

    but in new api [3.0.2] if I add any thing in $this->ANYTHING var it doesnt work in another function

    how can I solve that ??
     
  2. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    You forgot to add
    PHP:
    public $ANYTHING;
    before
    PHP:
    public function onEnable(){
     
  3. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    Dont do
    PHP:
    $sender->sendMessage("$this->ANYTHING");
    Instead, make it like this
    PHP:
    $sender->sendMessage($this->ANYTHING);
    Because ANYTHING is already a string so you dont have to put a string inside a string, also try this, under the class extends PluginBase write its public variable:
    PHP:
    public/private $ANYTHING;
     
    Muqsit and KHAV like this.
  4. abdullah

    abdullah Spider

    Messages:
    14
    GitHub:
    x3boodx
    the same problem
     
  5. Legoboy0215

    Legoboy0215 Witch

    Messages:
    64
    GitHub:
    legoboy0215
    Just a tip, but you can do this:
    PHP:
    $string "{$this->ANYTHING}";
    too. I know it might seem irrelevant, but it can turn out helpful sometimes when you have multiple inline expressions.
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Your plugin is not enabled and the class hasn't been loaded.
    If the plugin would have enabled, you'd get an error regarding the return value of onCommand().

    You haven't given sufficient information for us to debug your code. There has to be something going on in the console which should give you a hint.
     
  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.