Solved Config does not save

Discussion in 'Development' started by Anim', Oct 17, 2020 at 1:27 PM.

  1. Anim'

    Anim' Creeper

    Messages:
    4
    GitHub:
    AnimDev-FR
    Hello,
    Here is my code:
    PHP:
        public function levelUp(Player $player){
            
    $name $player->getName();
            
    $cfg = new Config(Main::getMainInstance()->getDataFolder() . "players.yml"Config::YAML);
            
    $beforeLevel $cfg->getNested("players.$name.level");
            
    $newLvl $beforeLevel 1;
            
    $player->sendTitle("§l§aLEVEL UP!""§l§a$beforeLevel §l§2⇛ §l§a$nouveauLvl");
            
    $cfg->setNested("players.$name.level"$newLvl);
            
    $cfg->save();
            }
    The title is sended but the config is not edited (no error is logged).
    Please help
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    494
    $nouveauLvl is undefined
    If it showed the title somehow without erroring, that just means that this part of the code is not being executed
     
  3. Anim'

    Anim' Creeper

    Messages:
    4
    GitHub:
    AnimDev-FR
    in my code $nouveauLvl is defined just I edited it to be english (newLvl and i forgot to edit all) to post on the forum
     
  4. Ayzrix

    Ayzrix Witch

    Messages:
    61
    GitHub:
    Ayzrix
    PHP:
    public function levelUp(Player $player){
            
    $name $player->getName();
            
    $cfg = new Config(Main::getMainInstance()->getDataFolder() . "players.yml"Config::YAML);
            
    $beforeLevel $cfg->getNested("players.$name.level");
            
    $newLvl $beforeLevel 1;
            
    $player->sendTitle("§l§aLEVEL UP!""§l§a$beforeLevel §l§2⇛ §l§a$newLvl");
            
    $cfg->set("players.{$name}.level"$newLvl);
            
    $cfg->save();
            }
     
  5. TPE(ImperialPE)

    TPE(ImperialPE) Creeper

    Messages:
    5
    GitHub:
    tpe
    Save the config on disable
     
  6. mmm545

    mmm545 Slime

    Messages:
    98
    GitHub:
    mmm545
    Why do they need to save the config onDisable even though they already saved it?
     
  7. TPE(ImperialPE)

    TPE(ImperialPE) Creeper

    Messages:
    5
    GitHub:
    tpe
    Never mind I didn't read the whole thread.
     
  8. Anim'

    Anim' Creeper

    Messages:
    4
    GitHub:
    AnimDev-FR
    nothing too
     
  9. wolfdale

    wolfdale Zombie Pigman

    Messages:
    494
    Try deleting the folder before starting the server, see if it creates the folder with the config inside.
     
  10. Anim'

    Anim' Creeper

    Messages:
    4
    GitHub:
    AnimDev-FR
    i do it to edit players.$name.xp and it works but idk why lvls don't works
     

Share This Page

  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.