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

Solved How to make a config file

Discussion in 'Development' started by MalakasPlayzMCPE, Apr 25, 2018.

  1. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I use this code. I want to make a config file with the line kills: 0 and another file with the line souls: 10
    No errors:
    PHP:
      public function onJoin(PlayerJoinEvent $event) {
         
    $kconfig = new Config($this->getDataFolder()."stats/kills/".strtolower($event->getPlayer()->getName()).".yml"Config::YAML);
         
    $kconfig->save();
         if(empty(
    $kconfig->get("kills"))){
            
    $kconfig->set("kills"0);
            
    $kconfig->save();
         }

         
    $sconfig = new Config($this->getDataFolder()."stats/souls/".strtolower($event->getPlayer()->getName()).".yml"Config::YAML);
         
    $sconfig->save();
         if(empty(
    $sconfig->get("souls"))){
            
    $sconfig->set("souls"10);
            
    $sconfig->save();
         }
      }
     
  2. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Wait, isn't this for checking if it is true or false? Anyways, same result...
     
  3. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Oh, and btw how to get the config file from another plugin?
     
  4. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I used this code: $soulscfg = new Config("/plugins/SkyWars/stats/souls/".strtolower($name).".yml", Config::YAML);
    $name is the player name
     
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I solved the second one, now what about the first issue?
     
  6. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Ok, this ended to a PocketMine error. @dktapps @SOFe set(); does not work. Do I do something wrong?
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    It works. You did something wrong. I don't know what you want to do, and you didn't explain what you want to do, therefore I don't know what you did wrong. Config is one of the oldest but rarely-changed classes in PocketMine, since January 2013 and widely used by almost every single plugin. If something is wrong, I would bet that by 99.9% chance it is your own fault. Perhaps you should check the conditions and try to figure out what you are trying to do?
     
  8. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I want to set a value to a config file. When a player joins I check if the value souls exist, if it doesn't I use $cfg->set("souls", 10); trying to set the souls value to 10 ($cfg is the config), but this does not work.
     
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You said the first issue isn't solved. Isn't the first issue about kills? Are you having problems with souls or kills?
     
  10. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Both, forgot I said for kills. I use the same code on both so both have this issue
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    How does it not work? Does it not save, or does it save something else, or some error occurred? Is it when it exists or when it does not exist?

    Note that !$config->get("kills") will return true if the "kills" entry does not exist or if it is zero. Use exists() isnetad of get() to check if it exists.
     
  12. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Ok, even if it exists, the set(); does not work. Thanks for the TIPs tho
     
  13. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    We can't help you if you don't provide the exact steps to test it, not just the code. The code (changed to exists()) itself would work under normal circumstances. It is more likely what you want is not what we expect you to want.
     
  14. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I have a server. A player joins. I want to set something to a config file when the player joins. If this value is already set, I do nothing. I used the code above. When I joined, this value did not get set. I made sure it did not already exist.
     
  15. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    And what is your code now?
     
  16. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    And the file itself is being created by the plugin, right?
     
  17. Eren5960

    Eren5960 Spider Jockey

    Messages:
    27
    GitHub:
    Eren5960
    PHP:
     public function onJoin(PlayerJoinEvent $event) {
         
    $n $event->getPlayer()->getName();
         
    $kconfig = new Config($this->getDataFolder()."stats/kills/".strtolower($n).".yml"Config::YAML);
         if(!
    $kconfig->get("kills")){
            
    $kconfig->set("kills"0);
            
    $kconfig->save();
         }
         
    $sconfig = new Config($this->getDataFolder()."stats/souls/".strtolower($n).".yml"Config::YAML);
         if(!
    $sconfig->get("souls")){
            
    $sconfig->set("souls"10);
            
    $sconfig->save();
         }
      }
     
  18. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I solved 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.