My code is working but why i have this error when the code run: Code: [20:10:19] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerChatEvent' to 'KICKMS v1.0.0': Undefined index: on KICKMS\Main [20:10:19] [Server thread/CRITICAL]: ErrorException: "Undefined index:" (EXCEPTION) in "KICKMS/src/KICKMS/Main" at line 772 This is 772 line: PHP: if($this->games[$this->getGameByPlayer($player)]["Status"] == "INGAME"){
This is $this->games: PHP: public $games = ["Game1" => ["Arena" => "RM-1", "Status" => "JOINABLE"]]; And this is getGameByPlayer function: PHP: public function getGameByPlayer($player){if(is_null($player)) return;foreach($this->games as $game => $value){if($value["Arena"] == $player->getLevel()->getFolderName()){return $game;}}}
PHP: $this->games[$this->getGameByPlayer($player)] Are you use that entry exists in $games? Note that game can be null/void in your getGameByPlayer() method, which equates to "" key. The error happens when you try accessing an index of an empty. PHP: $x = [];$x["INDEX"] === "SOMETHING";//Undefined index "INDEX"$x["INDEX"] = [];$x["INDEX"]["INDEX2"] === "SOMETHING";//Undefined index "INDEX2"
Thank you i made this function: PHP: public function inGame($player){if($this->getGameByPlayer($player) == ""){return false;}else{return true;}} and add it up of: PHP: if($this->games[$this->getGameByPlayer($player)]["Status"] == "INGAME"){ and became like this: PHP: if($this->inGame($player){if($this->games[$this->getGameByPlayer($player)]["Status"] == "INGAME"){//do something}} And it works, Solved!