Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Config help

Comments in 'Plugin Development' started by CrazedMiner, Jul 4, 2015.

  1. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I want to get all the arenas from a config and store them in an array but I can't get it to work, I'm sure someone knows PHP better than me and will be able to help :p

    Code:
    PHP:
    $normal = new Config($this->getDataFolder() . "Normal-Arenas.yml"Config::YAML, array(
            ));
        
    foreach((
    $normal->getAll()["Arenas"]) as $n) {
        
    $this->arenas $n;
    }
    Config:
    Code:
    Arenas:
        Arena:
            Name: "Arena"
            Player-1:
                X: 124
                Y: 8
                Z: 124
            Player-2:
                X: 120
                Y: 8
                Z: 120
        Arena2:
            Name: "Arena2"
            Player-1:
                X: 124
                Y: 8
                Z: 124
            Player-2:
                X: 120
                Y: 8
                Z: 120
    
    So basically I want $this->arenas = array("Arena1", "Arena2")
    Last edited: Jul 4, 2015
    iDirtPlayzMC likes this.
  2. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Anyone able to help?
  3. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    I'm trying but you're more better than me in coding ._.
    CrazedMiner likes this.
  4. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    I guess here you did wrong .-.
    PHP:
    foreach(($normal->getAll()["Arenas"]) as $n)
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Arena1 and Arena2 are keys. You are saving the values instead of the keyskeys.
    CrazedMiner likes this.
  6. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    so how would I get them into an array?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually you could have just done
    PHP:
    $this->arenas $normal->get("Arenas") ;
  8. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    ;-;
  9. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    so that means $this->arenas = array("Arena1", "Arena2")?
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No.
    $this->arenas = ["Arena1" => ["Name"=>"Arena1", ...], ...];
    CrazedMiner likes this.
  11. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    so if I do array_rand($this->arenas) It'll give me either Arena1 or Arena2 as an output?
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes
    You can also use array_keys($this->arenas) to get an array of only the names.
  13. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Just making sure bc it gives me a weird output when I convert it to a string :p

Share This Page

Advertisement