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.
\$\begingroup\$ \$\endgroup\$
2 - \$\begingroup\$ Are you able to post the original code? What's the reason you don't want to change it? \$\endgroup\$Jaybird– Jaybird2018-12-27 07:25:07 +00:00Commented Dec 27, 2018 at 7:25
- \$\begingroup\$ Good code is supposed to change on it's own as you add to it. \$\endgroup\$davidblackberry1– davidblackberry12018-12-27 20:47:49 +00:00Commented Dec 27, 2018 at 20:47
Add a comment |
1 Answer
\$\begingroup\$ \$\endgroup\$
1 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.
- \$\begingroup\$ No, adding a check would involve modifying existing code, which is what I'm trying to avoid. \$\endgroup\$davidblackberry1– davidblackberry12018-12-27 06:54:23 +00:00Commented Dec 27, 2018 at 6:54