Re: Disconnecting Event Handlers
Posted: 09 December 2019, 13:26
Hi,VanHlebar wrote: ↑ I will have to look at your solution. The problem that I have is that a player needs to have 3 different options when they click on a region of the map:
1. Move the King to that location
2. Move their Grande to that location
3. Place a Caballero into that region.
Yes each of these options are only available from a single State, it would be silly to display an error message for the first and second option when the user is trying to place a Caballero into a region. Once I have connected the onclick event to the div for the region for during the phase place King phase, if I don't disconnect it then it will still be there when the player moves to the next phase of the turn which is placing Caballeros.
In such cases, I connect this div (edit: as soon as it is placed, and I never disconnect it) to a onClickThisDiv() method, in which I check in which gamestate the click occurred (and other things if needed), to trigger the relevant action (moveKing(), moveGrande() or placeCaballero() methods in your case) or to display an error message relevant to the current situation.