Apr-12-2019, 10:48 AM
(Apr-12-2019, 12:59 AM)loomski Wrote: But then he will have to keep doing money = old_witch(money) and after that, money = blacksmith(money) and then every single time he wants to make a new function where he adds money or decrements money he will have to keep reassigning?
Yes, which will make it clear that money is being modified by that function call. If he's just got a bunch of oldwitch() and blacksmith(), it is not clear at all that money is used or modified by those functions. And when he runs into a bug with money changing or not changing as expected, it's going to be that much harder track down the bug and figure it out.
(Apr-12-2019, 12:59 AM)loomski Wrote: I don't know, maybe for this particular thing where he's just calling 2 functions and checking them maybe this might be the "best" way (lol) but if he wants to have a hundred of those types of functions, I don't know.
If he wants to have hundreds of these types of functions, then the hundreds of functions are a problem, not having to pass, return, and assign values. At that point he needs a generic function for handling purchases, and he needs to move the distinction between witches and blacksmiths into some data. At that point he should also switch to OOP, and money should become an attribute of the Player class, which is in turn an attribute of the Game class.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures