I am having some trouble getting specific items from an array that is in my config.yml file. Here is what I have tried: Code: $array = Main::getInstance()->config->get("Players"); $player1 = Main::getInstance()->getServer()->getPlayerExact($array[0]); //line 84 $player2 = Main::getInstance()->getServer()->getPlayerExact($array[1]); And the inside of my config file: Code: Players: - RedCraftPE - ItsMax123 Unfortunately, this is not working and I am getting this error: Code: Server thread/CRITICAL ErrorException: "Undefined offset: 0" (EXCEPTION) in "Plugin/src/RedCraftPE/Tasks/Task" at line 84 If it is not possible to get individual elements of an array in a config file like this please let me know the proper way to do so, and explain why the method I used doesn't work.
do a var_dump($array); to see the structure of the array so that you will know how to access certain parts of the array
It is telling me that the array is empty. Code: array(0) { } I am trying to get the name from the array while assuming that I don't know the name that I am trying to get. The array won't always have the same names in it.
I am like 98% sure that I am reading the correct file. Code: $this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML); I definitely know that this is the correct file because it is writing/reading data in the Main.php file, the problem occurs when I try and use the file in a scheduled repeating task.
Just to be sure, do a PHP: var_dump(Main::getInstance()->config->getAll()); You should at least see an array that is not empty
That helped me find the problem I think. I put that at the top of my task file and when it ran everything appeared to be normal, so I looked through everything that was there and found a piece of the file which may have been returning the wrong value.