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

Config and arrays

Comments in 'Plugin Development' started by JackboyPlay, Jun 15, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    How can I get datas from an array in a config?
    How can I create an array in a config?
    How can I set datas in an array in a config?
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    exactly like you handle normal arrays

    Config::set("array", $yourArray);
    Config::get("array");
    Last edited: Jun 15, 2016
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    There is no method Config::get(array $key), there is only Config::get(string $key)
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Config::get($yourArray) doesn't make any sense. First, that won't work because it wants a string. And, why would you get an array out of a config you already have($yourArray)??
    applqpak likes this.
  5. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    OOOPS
    I of course meant
    Config::set("array", $yourArray);
    Config::get("array");

    Sorry for the confusion
  6. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    No.
    To create an array in a config:
    PHP:
    $config = (new Config($plugin->getDataFolder() . "config.yml"Config::YAML, array(
    "array_example" => ["one""two""three"],
    )))->
    getAll();
    To return the array:
    PHP:
    return $config["array_example"];
    To return a value in the array:
    PHP:
    return $config["array_example"]["one"];
    To set a value in the array:
    PHP:
    $config["array_example"]["one"] = 1;
    Last edited: Jun 16, 2016
  7. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    -_- that's almost exactly what i posted. Just that you used getAll()
  8. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    PHP:
    $config = new Config(/*Whatever*/);
    // Set an array
    $config->set("arrayName"$array);
    // Get an array
    $array $config->get("arrayName");
    If you want manually create an array:
    Code:
    thisIsAnArray:
    - "first parameter"
    - "second parameter"
    
    I saw some people using tabs in an unidimensional array
    Code:
    array:
           - "first parameter"
           - "second parameter"
    
    And, no, never do it, it's a bad practice.
    Last edited: Jun 21, 2016
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You cannot use tabs in YAML files.
    MikkiMCPE, SOFe and applqpak like this.
  10. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    I can, in QWERTY keyboards, under the number "1", there is a key...
    What happen if you press it in a yaml file? :p

    Another thing is what happen when you enconde/decode it.
    applqpak likes this.
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    applqpak likes this.
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Y or Z axis?
  13. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Hey, you are smart. Like all LBSG members, no?

    It's like a law:

    You can comply it, but you can ignore it, and, if you read my last post...
    ↓↓↓↓
    ↑↑↑↑
    If you cannot see it, please, visit this website.
    http://www.glasses.com/

    ... also, I read that website before your likes-searcher post :p
  14. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I don't know what your problem is, to be honest. Please learn about YAML files and come back later.

    Also, it is not just a bad practice. As mentioned before, learn about YAML files.
    applqpak and Gamecrafter like this.
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    He apparently knows YAML. Calm, he did pointed out that tabs can not be used in yaml, even twice but you plainly ignored him :confused:

    @AndrewBit You showed unnecessary reaction
    SOFe, AndrewBit and applqpak like this.
  16. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    He actually didn't.
    "Never do it, it's a bad practice" does not mean that you cannot do it.
    "I can, in QWERTY keyboards, under the number "1", there is a key...
    What happen if you press it in a yaml file? " Same here. I don't see him telling that you cannot use them.
    SOFe and applqpak like this.
  17. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
  18. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Not everyone has the same sense of humor. You cannot expect that I understand it.
  19. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    And you cannot expect that I understand that you don't have a sense of humour.
    Back on the topic, I really don't understand what's wrong with tabs. If tabs are used in the whole file, it has no difference from a single space (YAML accepts single-space indents too)

    The only problem is that YAML developers are worried that they aren't used in the whole file :p
    Maybe this would give more reference to the argument between tabs and spaces: https://github.com/PocketMine/PocketMine-MP/pull/2110

Share This Page

Advertisement