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

Call To Function Get() On String?

Discussion in 'Development' started by Junkdude, Dec 4, 2016.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    My error is the following "call to function get() on string"
    Code:
    PHP:
    public function onBreak(BlockBreakEvent $event){
          
    $p $event->getPlayer();
          
    $name $p->getName();
          
          if(
    $event->getBlock()->GetId() == 1){
              
    $this->mininglevel $this->getDataFolder() . "mining.yml";
              
    $level $this->mininglevel->get($name); ##LINE THAT CAUSES PROBLEM
              
    $this->mininglevel->set($name,$level+1);
              
    $this->mininglevel->Save();
              
    $name->sendMessage("Mining Skill Is Now Level" $level);
            }
        }
     
  2. imYannic

    imYannic Baby Zombie

    Messages:
    113
    It should be:
    PHP:
    $this->mininglevel = new Config($this->getDataFolder() . "mining.yml"Config::YAML);
     
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    But I generated the yml file in my main class
     
  4. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Then remove that $this->miningLevel = ... part
     
  5. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Did that but now it generates in the home directory of the server
     
  6. BalAnce

    BalAnce Silverfish

    Messages:
    22
    GitHub:
    YaBoiBalAnce
    This shouldnt override it if it already exists. it is also the only way to get the get() function like how your using it
    PHP:
    $this->mininglevel = new Config($this->getDataFolder() . "mining.yml"Config::YAML);
     
  7. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    It's not overriding it, it generates in my home/root directory.
     
  8. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    How did you create it in the first place?
     
  9. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    its created with the $this->mininglevel code
     
  10. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    PHP:
    public function onBreak(BlockBreakEvent $event){
          
    $p $event->getPlayer();
          
    $name $p->getName();
         
          if(
    $event->getBlock()->GetId() == 1){
              
    $this->mininglevel = new Config($this->getDataFolder() . "mining.yml"Config::YAML);
              
    $level $this->mininglevel->get($name); ##LINE THAT CAUSES PROBLEM
              
    $this->mininglevel->set($name,$level+1);
              
    $this->mininglevel->Save();
              
    $name->sendMessage("Mining Skill Is Now Level. $level");
            }
        }
    This should work fine
     
  11. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    yeah but it doesnt generate in the plugins/mcmmo file it generates in the home one
     
  12. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    Did you do
    PHP:
    @mkdir($this->getDataFolder());
     
  13. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    no, do i call it in the main class or mining class
     
  14. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    I recommend doing it in the onEnable function in your main class.
     
  15. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    K so I make all the files in my main then just access them in my mining class?
     
  16. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    Yes, if you have a different class you have to do what you want like this
    PHP:
    public function onBreak(BlockBreakEvent $event){
          
    $p $event->getPlayer();
          
    $name $p->getName();
          
    $plugin $mainInstance //Make sure you have the instance of your Main class here ;
       
          
    if($event->getBlock()->GetId() == 1){
              
    $this->mininglevel = new Config($plugin->getDataFolder() . "mining.yml"Config::YAML);
              
    $level $this->mininglevel->get($name); ##LINE THAT CAUSES PROBLEM
              
    $this->mininglevel->set($name,$level+1);
              
    $this->mininglevel->Save();
              
    $p->sendMessage("Mining Skill Is Now Level. $level");
            }
        }
    If you need further assistance I suggest you show me all of your files, Im not sure on how your setting this up.
     
  17. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    I'd recommend just doing:
    PHP:
    PluginBase::saveResource("mining.yml");
    // $plugin is your main class that extends PluginBase 
    $plugin->saveResource("mining.yml");
    That way it generates your plugins data folder and will actually provide you with a file to open.
     
    LilCrispy2o9 likes this.
  18. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Where do i put that, i've been messing with code ever since i posted this thread
     
  19. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    In your onEnable() function inside your Main class.
     
  20. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    In a class. All you need is a reference to your plugins main instance.
     
    LilCrispy2o9 likes this.
  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.