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

Config SetAll

Discussion in 'Development' started by Teamblocket, Dec 24, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    My goal is to use setAll() to set the default config values if the config isn't found, but it doesn't work.
    PHP:
            if(!file_exists(($path $d 'config.yml'))){ // config file
                    
                
    $c = new Config($pathConfig::YAML);
                
    $c->setAll(['Economy-Plugin' => 'EconomyAPI',
                
    'Broadcast' => ['example1'],
                
    'Border' => 500,
                
    'AntiSpam-Delay' => 2.5,
                
    'Staff(s)' => ['homelyangel'],
                
    'Banned-Stuff' => [
                    
    'Words' => ['a_badword_example'],
                    
    'Items' => [7]
                ],
                
    'Prefix' => ' Help me'
                
    ]);
                
    $c->save();
            }
     
  2. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    $d is getDataFolder() from \pocketmine\plugin\PluginBase
     
  3. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Try add the array into the constructor.

    PHP:
    $data = ['Economy-Plugin' => 'EconomyAPI',
                
    'Broadcast' => ['example1'],
                
    'Border' => 500,
                
    'AntiSpam-Delay' => 2.5,
                
    'Staff(s)' => ['homelyangel'],
                
    'Banned-Stuff' => [
                    
    'Words' => ['a_badword_example'],
                    
    'Items' => [7]
                ],
                
    'Prefix' => ' Help me'
                
    ];

    $config = new Config($pathConfig::YAML$data);
     
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    I found my error , so in my Main class i was trying to get the 'Prefix' value even before it was created so it just created a blank config , i put the line under the function where i start this function and it worked.
     
  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.