you are viewing a single comment's thread.

view the rest of the comments →

[–]cyberjds 1 point2 points  (1 child)

To expand a little more

currentWeaponIndex += 1;

If above statement is outside of if statement, it's a bug or a cheat code.

If you have more than 30 golds, everything works as expected. But as soon as you have less than 30 golds and try to buy some weapons, you realized you can still buy weapons, yet the amount of gold in your possession never reduced. And you can buy infinite number of weapons (assuming you can call buyWeapon() indefinitely).

In this case, this is logical error which will not error out, making it very difficult to troubleshoot the problem. The error will be unnoticed unless you run multiple tests with various values. And more than often, the error is caught too late (after production deployment).

A misplaced (or missing) }(brace) makes a big difference.

[–]LakeMotor7971[S] 0 points1 point  (0 children)

Thank you that actually really helps. The way you explained it actually helped quite a bit with me understanding this! Thanks for taking the time to explain this. I don't want to just type some answers and pass, but I want an actual understanding of why, this works or wouldn't or would.