Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Fix Bug #3: Power battles
This is another subtle bug that crops up frequently in many different forms. The problem is that this line: ``` player_stats['power'] = player_stats['power'] - enemy_stats['power'] ``` PERMANENTLY modifies the value of `player_stats['power']`. It even modifies the variable *outside* of the function it is inside. This is why it appears as though our player's power is slowly draining away. The fix is to change our code so that it doesn't modify `player_stats`: ``` power_diff = player_stats['power'] - enemy_stats['power'] ``` For much more detail on when and why functions can modify data outside of themselves, see: https://robertheaton.com/2014/02/09/pythons-pass-by-object-reference-as-explained-by-philip-k-dick/
- Loading branch information