so i built a basic inventory for the gamebook im working on in Harlowe 1.2.3 based almost exactly off of this site:
http://gersande.com/blog/designing-inventories-in-twine-2-with-the-built-in-harlowe-macros/
the difference is that inside of my inventory i also keep record of various statistics (karma, money and a few others) which change throughout the book using
(set: $karma to $karma + 1)
now my issue comes in when i use the return button in my inventory
(link-goto: "Return", (history:)'s last)
to return to a passage where i gain or lose stats it will run the code again and add or subtract from my stats a second time thus making a way to cheat the stat system. Is there anyway to make it so it will only run a certain bar of code once? any help would be greatly appreciated!
Thanks
-Chrisgbw
Comments
There's a couple of options. The first is in my opinion the best: tie code that shouldn't rerun to player action, not story position. In other words, clicking the link should generally run code that increments variables, while variables that are altered in a discreet, specific manner (changes from true to false or to other discreet values) are fine in-passage.
For example, if you need to know that the player has reached chapter 2,
is fine to include in the passage. No matter how many times the player visits the passage, it won't mess anything up behind the scenes.
On the other hand:
Can be a problem when included in any passage code where there's even a slight chance the player may revisit. So go back one passage and alter the link code. Instead of:
You probably want something like:
That is not the only way to solve the issue, though. Looking over Harlowe's documentation, and I'm pretty sure you can use a combination of (if:) (history:) and (passage:) macros to test if the user has visited the current passage before, but that's a lot more work for no payoff, in my opinion.
[Note that I didn't test the above code so it may include a typo or something. Probably should have and usually do, but like I said, this seems like more of a design thing.]