haxball / haxball-issues

114 stars 42 forks source link

Help Error [TypeError: Cannot read property 'id' of undefined] #1176

Open qoksel00 opened 3 years ago

qoksel00 commented 3 years ago

I get the error on the right in the picture, after a certain time it gives this error the bot crash https://i.hizliresim.com/gCopeu.png `function updateRoleOnPlayerIn() { updateTeams(); if (inChooseMode) { if (players.length == 6) { loadMap(bigMap, scoreLimitBig, timeLimitBig); } getSpecList(teamR.length <= teamB.length ? teamR[0] : teamB[0]); } balanceTeams(); }

function updateRoleOnPlayerOut() { updateTeams(); if (room.getScores() != null) { var scores = room.getScores(); if (players.length >= 2 maxTeamSize && scores.time >= (5/6) game.scores.timeLimit && teamR.length != teamB.length) { if (teamR.length < teamB.length) { if (scores.blue - scores.red == 2) { endGame(Team.BLUE); room.sendChat("🤖 Ragequit Tespit Edildi. Oyun Bitti 🤖"); setTimeout(() => { room.stopGame(); }, 100); return; } } else { if (scores.red - scores.blue == 2) { endGame(Team.RED); room.sendChat("🤖 Ragequit Tespit Edildi. Oyun Bitti 🤖"); setTimeout(() => { room.stopGame(); }, 100); return; } } } } if (inChooseMode) { if (players.length == 5) { loadMap(classicMap, scoreLimitClassic, timeLimitClassic); } if (teamR.length == 0 || teamB.length == 0) { teamR.length == 0 ? room.setPlayerTeam(teamS[0].id, Team.RED) : room.setPlayerTeam(teamS[0].id, Team.BLUE); return; } if (Math.abs(teamR.length - teamB.length) == teamS.length) { room.sendChat("🤖 Hiç Seçenek Kalmadı. Bu Durumu Bot Hallediyor... 🤖"); deactivateChooseMode(); resumeGame(); var b = teamS.length; if (teamR.length > teamB.length) { for (var i = 0 ; i < b ; i++) { setTimeout(() => { room.setPlayerTeam(teamS[0].id, Team.BLUE); }, 5i); } } else { for (var i = 0 ; i < b ; i++) { setTimeout(() => { room.setPlayerTeam(teamS[0].id, Team.RED); }, 5i); } } return; } if (streak == 0 && room.getScores() == null) { if (Math.abs(teamR.length - teamB.length) == 2) { // if someone left a team has 2 more players than the other one, put the last chosen guy back in his place so it's fair room.sendChat("🤖 Takımlar Dengeleniyor... 🤖"); teamR.length > teamB.length ? room.setPlayerTeam(teamR[teamR.length - 1].id, Team.SPECTATORS) : room.setPlayerTeam(teamB[teamB.length - 1].id, Team.SPECTATORS); } } if (teamR.length == teamB.length && teamS.length < 2) { deactivateChooseMode(); resumeGame(); return; } capLeft ? choosePlayer() : getSpecList(teamR.length <= teamB.length ? teamR[0] : teamB[0]); } balanceTeams(); }

function balanceTeams() { if (!inChooseMode) { if (players.length == 1 && teamR.length == 0) { quickRestart(); loadMap(aloneMap, 0, 0); room.setPlayerTeam(players[0].id, Team.RED); } else if (Math.abs(teamR.length - teamB.length) == teamS.length && teamS.length > 0) { const n = Math.abs(teamR.length - teamB.length); if (players.length == 2) { quickRestart(); loadMap(classicMap, scoreLimitClassic, timeLimitClassic); } if (teamR.length > teamB.length) { for (var i = 0 ; i < n ; i++) { room.setPlayerTeam(teamS[i].id, Team.BLUE); } } else { for (var i = 0 ; i < n ; i++) { room.setPlayerTeam(teamS[i].id, Team.RED); } } } else if (Math.abs(teamR.length - teamB.length) > teamS.length) { const n = Math.abs(teamR.length - teamB.length); if (players.length == 1) { quickRestart(); loadMap(aloneMap, 0, 0); room.setPlayerTeam(players[0].id, Team.RED); return; } else if (players.length == 5) { quickRestart(); loadMap(classicMap, scoreLimitClassic, timeLimitClassic); } if (players.length == maxTeamSize * 2 - 1) { allReds = []; allBlues = []; } if (teamR.length > teamB.length) { for (var i = 0 ; i < n ; i++) { room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS); } } else { for (var i = 0 ; i < n ; i++) { room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS); } } } else if (Math.abs(teamR.length - teamB.length) < teamS.length && teamR.length != teamB.length) { room.pauseGame(true); activateChooseMode(); choosePlayer(); } else if (teamS.length >= 2 && teamR.length == teamB.length && teamR.length < maxTeamSize) { if (teamR.length == 2) { quickRestart(); loadMap(bigMap, scoreLimitBig, timeLimitBig); } topBtn(); } } }

function choosePlayer() { clearTimeout(timeOutCap); if (teamR.length <= teamB.length && teamR.length != 0) { room.sendChat("[PV] Bir oyuncu seçmek için verilen listeye numarasını girin 'Üst', 'Rastgele' Veya 'Alt'.", teamR[0].id); timeOutCap = setTimeout(function (player) { room.sendChat("[PV] Acele Et @" + player.name + ", only " + Number.parseInt(chooseTime / 2) + " Saniye Kaldı Seçmen İçin !", player.id); timeOutCap = setTimeout(function (player) { room.kickPlayer(player.id, " Zamanında Seçmedin !", false); }, chooseTime 500, teamR[0]); }, chooseTime 1000, teamR[0]); } else if (teamB.length < teamR.length && teamB.length != 0) { room.sendChat("[PV] Bir oyuncu seçmek için verilen listeye numarasını girin 'Üst', 'Rastgele' Veya 'Alt'.", teamB[0].id); timeOutCap = setTimeout(function (player) { room.sendChat("[PV] Acele Et @" + player.name + ", only " + Number.parseInt(chooseTime / 2) + " Saniye Kaldı Seçmen İçin !", player.id); timeOutCap = setTimeout(function (player) { room.kickPlayer(player.id, " Zamanında Seçmedin !", false); }, chooseTime 500, teamB[0]); }, chooseTime 1000, teamB[0]); } if (teamR.length != 0 && teamB.length != 0) getSpecList(teamR.length <= teamB.length ? teamR[0] : teamB[0]); }

function getSpecList(player) { var cstm = "[PV] Oyuncular : "; for (var i = 0 ; i < teamS.length ; i++) { if (140 - cstm.length < (teamS[i].name + "[" + (i+1) + "], ").length) { room.sendChat(cstm, player.id); cstm = "... "; } cstm += teamS[i].name + "[" + (i+1) + "], "; } cstm = cstm.substring(0,cstm.length - 2); cstm += "."; room.sendChat(cstm, player.id); } `

thenorthstar commented 3 years ago

@qoksel00 Do you get this error when every player joins?

qoksel00 commented 3 years ago

@qoksel00 Do you get this error when every player joins?

No, by the way, the game freezes and throws everyone, what's the reason? how can we solve @thenorthstar

thenorthstar commented 3 years ago

I'm not sure but you can make undefined controls on if's and else's. Firstly try this, if not, write here again.

qoksel00 commented 3 years ago

@thenorthstar the problem continues bot this can you check it

https://hastebin.com/afasozawep.swift

thenorthstar commented 3 years ago

Dude, I have just tested your room in public and didn't face with any errors. Also I have invoked manually the function which you claim give errors. And again I didn't face with any errors.

qoksel00 commented 3 years ago

Dude, I have just tested your room in public and didn't face with any errors. Also I have invoked manually the function which you claim give errors. And again I didn't face with any errors.

You still make the same mistake man, you keep the room open.You will not wait for a while after a few games, when the match is over, it does not throw the man into the rejection team, it freezes, the game freezes, everyone has to go out