I basically need something that modifies existing code without the need to go back and change it. So for instance, if I have a game where the player or NPS can eat food to gain health back, and eating a banana gives five health, how can I make a trait that will make the banana gives ten health instead of five without going back into the original code that makes the banana award five health? Thanks.
Asked
Active
Viewed 153 times
0
-
Are you able to post the original code? What's the reason you don't want to change it? – Jaybird Dec 27 '18 at 07:25
-
Good code is supposed to change on it's own as you add to it. – davidblackberry1 Dec 27 '18 at 20:47
1 Answers
0
I would suggest adding a conditional to the action, so if the player has that trait it would raise a flag, and every time the character eats a banana it would check using a if else and if the user has that trait it would heal the 10 instead of 5, hope that helps.

Ender White
- 1
- 1
-
No, adding a check would involve modifying existing code, which is what I'm trying to avoid. – davidblackberry1 Dec 27 '18 at 06:54