9 years ago by BennyT
Hi all, I am working on a sports game and I have been trying to debug this issue for the last two days and not making much progress and would appreciate some help.
I have moved my player control functions into a separate entity's update method, and there is a variable where I keep a reference to the entity I wish to control.
The issue though is this conditional statement in the update method:
that goes and finds the player's team and looks for the new entity to give control to.
The method that gets called looks like this (I have simplified the team to two entities for debugging purposes):
The reason why some of the lines are commented out is because when I run the Chrome debugger, after it has done one pass, even though I have only pressed the key once, it goes back again, so it always ends up with the same entity with the control.
When the lines remained commented out, it still runs twice, but the correct entity receives control.
What am I doing wrong????
Thanks for your help in advance!
I have moved my player control functions into a separate entity's update method, and there is a variable where I keep a reference to the entity I wish to control.
The issue though is this conditional statement in the update method:
if (ig.input.pressed('switch') ) { console.log('pressed switch'); ig.game.getEntitiesByType('EntityTeam')[0].giveOtherPlayerControl(); }
that goes and finds the player's team and looks for the new entity to give control to.
The method that gets called looks like this (I have simplified the team to two entities for debugging purposes):
giveOtherPlayerControl: function() { var controlledPlayer = this.findPlayerWithControl(); if(controlledPlayer.playerNumber >= 1 ) { console.log("this player number: " + this.playersInTeam[1].playerNumber); //controlledPlayer.controlObject = null; //controlledPlayer.controller = "computer"; //this.playersInTeam[0].controller = "player"; //this.playersInTeam[0].controlObject = new EntityPcontrols(0,0, {player: this.playersInTeam[0]}); } else { console.log("this player number: " + this.playersInTeam[0].playerNumber); controlledPlayer.controlObject = null; controlledPlayer.controller = "computer"; this.playersInTeam[1].controller = "player"; this.playersInTeam[1].controlObject = new EntityPcontrols(0,0, {player: this.playersInTeam[1]}); } },
The reason why some of the lines are commented out is because when I run the Chrome debugger, after it has done one pass, even though I have only pressed the key once, it goes back again, so it always ends up with the same entity with the control.
When the lines remained commented out, it still runs twice, but the correct entity receives control.
What am I doing wrong????
Thanks for your help in advance!