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. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Your issue seems to big. Can you try to simplify it and explain what exactly you need after so much discussion?
     
  2. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I still get the same issue as the the title, I don't know how to fix it and I've tried re-reading the links you have posted multiple times.
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Load data using yaml_parse_file($file). Store data using yaml_emit_file($file).
    Don't assume you are using Config class. yaml_parse_file() returns an associative array.
    But I think using objects are better than using associative arrays.

    https://php.net/yaml
     
    Last edited: Dec 11, 2016
  4. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    They've been telling you this whole time how to fix it.
    This:
    PHP:
    $this->mininglevel $this->plugin->getDataFolder() . "mininglevel.yml";
    defines your $this->mininglevel variable as a string. Note that the arrow (->) is only used when calling a variable or method inside an object. A string is not an object!
    This:
    PHP:
    $this->mininglevel = new Config($this->plugin->getDataFolder() . "mininglevel.yml");
    defines your $this->mininglevel variable as a config object. Now you can use the arrow (->) to call the methods that you want.

    All config methods here: https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/utils/Config.php
    What is an object? http://php.net/manual/en/language.types.object.php
    What is a string? http://php.net/manual/en/language.types.string.php
     
  5. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Can I please have the code to fix it.
     
  6. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I had fixed it with this, but now I generate the playerfiles on join so this doesnt work.
     
  7. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Ignore the last 2 posts, now I'm getting a set() on integer error,
    Updated Mining.php:

    PHP:
    <?php

    namespace MCMMOPE\Skills;

    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat as c;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\Cancellable;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    MCMMOPE\Loader;
    use 
    pocketmine\entity\Effect;

    class 
    Mining extends PluginBase implements Listener{
        public function 
    dataPath()
        {
          return 
    $this->getDataFolder();
        }
      public 
    $mining;

        public function 
    __construct(Loader $plugin){
              
    $this->loader $plugin;
        }

        public function 
    getPlugin() {
            return 
    $this->plugin;
        }



        public function 
    onBreak(BlockBreakEvent $event){
          
    $player $event->getPlayer();
          
    $name $player->getName();
          
    $this->PlayerFile = new Config($this->loader->getDataFolder()."Users/".$player->getName().".yml"Config::YAML);
          
    $data $this->PlayerFile->get("MiningEXP");
              if(
    $event->getBlock()->GetId() == 1){
              
    $data->set(+1);
              
    $this->PlayerFile->save();
    }
    }

        
    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){

      if(
    strtolower($cmd->getName()) === "activate_mining"){
      
    $dataFile $this->loader->getDataFolder() . strtolower($sender->getName());
      
    $name $sender;
      if(
    is_file($dataFile)) {
        
    $data yaml_parse_file($dataFile);
        
    $lastTime $data["last-execute-command"][$cmd->getName()];
      } else {
        
    $lastTime 0;
      }
      if(
    time() - $lastTime 5) {
        
    $sender->sendMessage("You execute too frequently!");
        return 
    true;
      }else if(
    time() - $lastTime 5) {
        
    $sender->SendMessage("Skill Activated");
        
    ##if($name->)
        ##$name->addEffect(Effect::getEffect(20)->setDuration($duration)->setAmplifier(1));
     
    }
    $data["last-execute-command"][$cmd->getName()] = time();
      
    yaml_emit_file($dataFile$data);
      
    // handle command
      
    return true;
    }
    }
    }
     
  8. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    What do you think you are doing? $data is the value for MiningXP. It is not a Config object, nor any reference to the config. If you are going to increment it, modify it normally like how you do with variables, and set() the new value into the config similar to how you get() it.
     
  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.