Lesson 99.2 – Setting CurrentWeapon when the player has multiple weapons

A student found a bug with the CurrentWeapon being reset when the player has multiple weapons.


Bug Description

There are times when the player’s CurrentWeapon is reset in their weapon dropdown combobox.


Bug Fix

To fix this bug, you need to modify the PlayerOnPropertyChanged() function (lines 113 through 132 below), in SuperAdventure.cs.

If the player’s “Weapons” property changed, we save their CurrentWeapon value to a variable, before resetting the DataSource on the combobox.

Then, if the player had a previously-selected weapon (the variable is not null), we set the SelectedItem in the combobox to the weapon.






If you have any problems applying this change, or notice any other bugs, please leave a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *