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(); } }
I used this code: $soulscfg = new Config("/plugins/SkyWars/stats/souls/".strtolower($name).".yml", Config::YAML); $name is the player name
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?
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.
You said the first issue isn't solved. Isn't the first issue about kills? Are you having problems with souls or kills?
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.
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.
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.
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(); } }