0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Are you able to post the original code? What's the reason you don't want to change it? \$\endgroup\$
    – Jaybird
    Dec 27, 2018 at 7:25
  • \$\begingroup\$ Good code is supposed to change on it's own as you add to it. \$\endgroup\$ Dec 27, 2018 at 20:47

1 Answer 1

0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ No, adding a check would involve modifying existing code, which is what I'm trying to avoid. \$\endgroup\$ Dec 27, 2018 at 6:54

Not the answer you're looking for? Browse other questions tagged .