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

Another config.yml issue: ARRAYS

Comments in 'Plugin Development' started by AndrewBit, Jan 15, 2016.

  1. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    I'm starting to hate yaml files...
    The method that I usually use:
    PHP:
    @mkdir($this->getDataFolder());
    $this->saveDefaultConfig();
    $this->reloadConfig();
    $this->config $this->getConfig()->getAll();
    How I can get an array from yaml? And, how I can write it as well?
    My (useless) method:
    PHP:
    # MySQL settings
    MySQL:
      - 
    Host"127.0.0.1"
      
    User"user"
      
    Password"password"
      
    Database"user_data"
    How I (try) get it:
    PHP:
    $this->config["MySQL"]->Host;
    # I also tried
    /*
    * $this-config["MySQL"]["Host"];
    */
    Last edited: Jan 15, 2016
  2. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Just use
    PHP:
    $this->config["MySQL"]["Host"];
    It will work
  3. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Code:
    [23:51:41] [CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerPreLoginEvent' to 'PocketRB vAdara #1': Undefined index: Host on andrew\EventListener
    [23:51:41] [NOTICE]: ArrayOutOfBoundsException: "Undefined index: Host" (E_NOTICE) in "/PocketRB source/src/andrew/PocketRB" at line 51
    
  4. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    I don't know if this will make any difference, but usually if I do that method, the config file will look like this
    Code:
    MySQL:
      Host: "blablabla"
    AndrewBit likes this.
  5. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    I don't have any experience with yaml files :D
  6. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Working! ❤
    Vaivez66 likes this.
  7. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Now I'm getting another error... (This time using multidimensional arrays...)
    Code:
    [00:12:54] [CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'PocketRB vAdara #1': Undefined index: y on andrew\EventListener
    [00:12:54] [NOTICE]: ArrayOutOfBoundsException: "Undefined index: y" (E_NOTICE) in "/PocketRB source/src/andrew/PocketRB" at line 58
    
    Yaml:
    Code:
    Positions:
      RB-1:
        StartPosition:
          x: 22
          y: 62
          z: -61
        BeastPosition:
          x: 29
          y: 65
          z: -62
        LobbyPosition:
          x: 21
          y: 65
          z: -70
        MiddlePosition:
          x: 1
          y: 72
          z: -14
      RB-2:
        StartPosition:
          x: 22
          y: 62
          z: -61
        BeastPosition:
          x: 29
          y: 65
          z: -62
        LobbyPosition:
          x: 21
          y: 65
          z: -70
        MiddlePosition:
          x: 1
          y: 72
          z: -14
      RB-3:
        StartPosition:
          x: 22
          y: 62
          z: -61
        BeastPosition:
          x: 29
          y: 65
          z: -62
        LobbyPosition:
          x: 21
          y: 65
          z: -70
        MiddlePosition:
          x: 1
          y: 72
          z: -14
      RB-4:
        StartPosition:
          x: 22
          y: 62
          z: -61
        BeastPosition:
          x: 29
          y: 65
          z: -62
        LobbyPosition:
          x: 21
          y: 65
          z: -70
        MiddlePosition:
          x: 1
          y: 72
          z: -14
      RB-5:
        StartPosition:
          x: 22
          y: 62
          z: -61
        BeastPosition:
          x: 29
          y: 65
          z: -62
        LobbyPosition:
          x: 21
          y: 65
          z: -70
        MiddlePosition:
          x: 1
          y: 72
          z: -14
      RB-6:
        StartPosition:
          x: 22
          y: 62
          z: -61
        BeastPosition:
          x: 29
          y: 65
          z: -62
        LobbyPosition:
          x: 21
          y: 65
          z: -70
        MiddlePosition:
          x: 1
          y: 72
          z: -14
      RB-7:
        StartPosition:
          x: 22
          y: 62
          z: -61
        BeastPosition:
          x: 29
          y: 65
          z: -62
        LobbyPosition:
          x: 21
          y: 65
          z: -70
        MiddlePosition:
          x: 1
          y: 72
          z: -14
      RB-8:
        StartPosition:
          x: 22
          y: 62
          z: -61
        BeastPosition:
          x: 29
          y: 65
          z: -62
        LobbyPosition:
          x: 21
          y: 65
          z: -70
        MiddlePosition:
          x: 1
          y: 72
          z: -14
      RB-9:
        StartPosition:
          x: 22
          y: 62
          z: -61
        BeastPosition:
          x: 29
          y: 65
          z: -62
        LobbyPosition:
          x: 21
          y: 65
          z: -70
        MiddlePosition:
          x: 1
          y: 72
          z: -14
      RB-10:
        StartPosition:
          x: 22
          y: 62
          z: -61
        BeastPosition:
          x: 29
          y: 65
          z: -62
        LobbyPosition:
          x: 21
          y: 65
          z: -70
        MiddlePosition:
          x: 1
          y: 72
          z: -14
    How I call it:
    PHP:
    public function getGamePosition($game,$POSITION_TYPE,$pos){
            
    # ex: $this->getGamePosition("RB-1","StartPosition","x");
            
    return $this->config["Positions"][$game][$POSITION_TYPE][$pos];
        }
  8. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Maybe your config file need to look like this
    Code:
    StartPosition:
      x:
      "y":
      z:
    
    I don't know why, but it works on my plugin
  9. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    I notice it has something to do with Vector3
  10. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Not working...
    Code:
    [00:31:10] [WARNING]: RuntimeException: "yaml_parse(): parsing error encountered during parsing: did not find expected key (line 31, column 7), context while parsing a block mapping (line 29, column 5)" (E_WARNING) in "/src/pocketmine/utils/Config" at line 148
    [00:31:10] [INFO]: Disabling PocketRB vAdara #1
    [00:31:10] [INFO]: [PocketRB] PocketRB - Adara #1 disabled
    
    Code:
    Positions:
      RB-1:
        StartPosition:
           x: 22
          "y": 62
           z: -61
        BeastPosition:
          x: 29
          "y": 65
          z: -62
        LobbyPosition:
          x: 21
          "y": 65
          z: -70
        MiddlePosition:
          x: 1
          "y": 72
          z: -14
      RB-2:
        StartPosition:
          x: 22
          "y": 62
          z: -61
        BeastPosition:
          x: 29
          "y": 65
          z: -62
        LobbyPosition:
          x: 21
          "y": 65
          z: -70
        MiddlePosition:
          x: 1
          "y": 72
          z: -14
      RB-3:
        StartPosition:
          x: 22
          "y": 62
          z: -61
        BeastPosition:
          x: 29
          "y": 65
          z: -62
        LobbyPosition:
          x: 21
          "y": 65
          z: -70
        MiddlePosition:
          x: 1
          "y": 72
          z: -14
      RB-4:
        StartPosition:
          x: 22
          "y": 62
          z: -61
        BeastPosition:
          x: 29
          "y": 65
          z: -62
        LobbyPosition:
          x: 21
          "y": 65
          z: -70
        MiddlePosition:
          x: 1
          "y": 72
          z: -14
      RB-5:
        StartPosition:
          x: 22
          "y": 62
          z: -61
        BeastPosition:
          x: 29
          "y": 65
          z: -62
        LobbyPosition:
          x: 21
          "y": 65
          z: -70
        MiddlePosition:
          x: 1
          "y": 72
          z: -14
      RB-6:
        StartPosition:
          x: 22
         "y": 62
          z: -61
        BeastPosition:
          x: 29
          "y": 65
          z: -62
        LobbyPosition:
          x: 21
          "y": 65
          z: -70
        MiddlePosition:
          x: 1
          "y": 72
          z: -14
      RB-7:
        StartPosition:
          x: 22
          "y": 62
          z: -61
        BeastPosition:
          x: 29
          "y": 65
          z: -62
        LobbyPosition:
          x: 21
          "y": 65
          z: -70
        MiddlePosition:
          x: 1
          "y": 72
          z: -14
      RB-8:
        StartPosition:
          x: 22
          "y": 62
          z: -61
        BeastPosition:
          x: 29
          "y": 65
          z: -62
        LobbyPosition:
          x: 21
          "y": 65
          z: -70
        MiddlePosition:
          x: 1
          "y": 72
          z: -14
      RB-9:
        StartPosition:
          x: 22
          "y": 62
          z: -61
        BeastPosition:
          x: 29
          "y": 65
          z: -62
        LobbyPosition:
          x: 21
          "y": 65
          z: -70
        MiddlePosition:
          x: 1
          "y": 72
          z: -14
      RB-10:
        StartPosition:
          x: 22
          "y": 62
          z: -61
        BeastPosition:
          x: 29
          "y": 65
          z: -62
        LobbyPosition:
          x: 21
          "y": 65
          z: -70
        MiddlePosition:
          x: 1
          "y": 72
          z: -14
    ...
  11. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Maybe I do something wrong. Change it back. Maybe some major dev can help with it
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I prefer $config->get() instead of getAll().
    Vaivez66 likes this.
  13. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    I wonder why the undefined index just "y"
  14. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    I hate yaml syntax... :oops:
    PocketKiller, KubixQ and Vaivez66 like this.
  15. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    This won't fix my problem...
  16. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Of course it won't xD. It's different method
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you use $this->***Config() functions, do not override $this->config.
    HotFireyDeath, wolfdale and Vaivez66 like this.
  18. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Bump. I still need to know how to fix my yaml...
  19. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    No one can help with it? I want to know how to fix it too...
  20. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Here is a simple workaround for that issue you are having.
    Simply replace all the x, y, z variables with -.

    Example:
    OLD
    Code:
    x: 23
    y: 22
    z: 19
    
    NEW
    Code:
    - "23"
    - "22"
    - "19"
    
    Then, access with 0(x), 1(y), 2(z) as the indexes. The problem should now be fixed.
    PHP:
    // your old way
    # ex: $this->getGamePosition("RB-1","StartPosition","x");
    // your new way
    # ex: $this->getGamePosition("RB-1","StartPosition", 0);

    ---
    Edit:

    The same thing for your example of MySQL at the top.
    Instead of:
    Code:
    MySQL:
     - Host: "127.0.0.1"
    
    do
    Code:
    MySQL:
     - "127.0.0.1"
    
    for each of the "indexes", and access them in order starting from 0.
    Last edited: Jan 17, 2016
    AndrewBit likes this.

Share This Page

Advertisement