I once again have a logic error. This time I am positively baffled: I am making a function that messes with three vectors it receives as parameters. The function adds new items to those vectors, but the funny thing is, while it completely normally adds items to two of the three, it fails to do so for the first, despite the fact that I use the same template! Here the function is:
In one case you are using push_back. in others you are replacing values at indices 0 and 1. Also I noticed, you are using binary_search. Note, that function works correctly only on sorted sequences! If your vector isn't sorted it probably just give you false every time. Who told you to use that useless function?
I can see how that would affect things, however, binary_search does not fail, as I am informed that my reward is two new spells. However, when I go back into combat and view my spells, it goes to the defaults I have set. In fact, the function apparently does not even alter magicDamage, as my spells still do the same damage...
However, what would a better function be for probing collections for specific elements?
I do not see what is the problem with your function. Maybe some other code alters vector of spells?
Also you are passing your player variable as copy: no changes to it will be visible outside function.
To search for specific item in unsorted container use std::find http://en.cppreference.com/w/cpp/algorithm/find
Or in your case you can simply check what first element is.
I tried various solutions, including passing the instance in by reference and passing the individual magicDamage and magicHeal variables in by reference, but the problem still persists! The thing is, this function works fine with my armor and weapons rewards, as in, the weapons and armor are all delivered, they show up in my inventory and all, but the spells simply won't appear, and the modifications to the damage and heal values also do not work...
I seem to have found the problem: the truth is, this function works fine, but all the values are lost. I have a visitVillage() global function which this will return to, and I have checked that. All the spells and modified values are fine there. However, when visitVillage() returns to play(), the body function, also global, not only are the spells and their associated values lost, but any alterations to the character are lost... is there some crazy trick I can use to preserve my values?
However, I managed to solve the problem using some saving and loading tricks (I save player information when he returns from his quest, where the information is preserved, and then I load it back up when the program returns to play()).