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

Solved Can't set to config (PMMP BUG?)

Discussion in 'Development' started by Kyd, Oct 9, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I'm trying to set value to config , but it's not working (It keep old value) please help me
    PHP:
    public function getConfig() : Config{
    return new 
    Config(Loader::getInstance()->getDataFolder() . "/test/" $this->getSessionName() . ".json"Config::JSON);
    }
    So, getConfig() returns valid config object

    Then I'm setting value to config
    PHP:
    $test->getConfig()->set("all""$b[3]");
    $test->getConfig()->save();
    Code is 100% executed, but it don't work (I must point to "all" already exists in config before setting)
    When I go to json file and remove "all" then code works and set "all" :/

    Edit: I tried to set normal string like $test->getConfig("set", "test"); and it still don't work
     
    Last edited: Oct 9, 2017
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    You need to use set in the first call, not save:
    PHP:
    $test->getConfig()->set("all", (string) $b[3]);
    $test->getConfig()->save();
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Sorry it was only typo when I was posting code here (I'm going to correct it) , but in my plugin I have $test->getConfig()->set("all", "$b[3]");
    instead of save() and problem still happens.
     
  4. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    You must do:
    PHP:
    $config $test->getConfig();
    $config->set("all"$b[3]);
    $config->save(); 
    With your method it creates the config, changes in the config something without saving the changes.
    Then he creates again a config and saves the unchanged config.
     
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Oh, now I see the problem. you discard everything you have changed by creating a new cfg object. either save your object in getConfig (for example as a class member/variable or do this:
    PHP:
    $cfg $test->getConfig();
    $cfg->set("all", (string) $b[3]);
    $cfg->save();
    or change your getConfig function:
    PHP:
    public function getConfig() : Config{
        if(!isset(
    $this->config) || (!$this->config instance Config)){
            
    $this->config = new Config(Loader::getInstance()->getDataFolder() . "/test/" $this->getSessionName() . ".json"Config::JSON);
        }
        return 
    $this->config;
    }
     
  6. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    and two posts at the same time :)
     
  7. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    yes :D
    But I was faster xD
     
  8. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Thanks guys
     
  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.