Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Variables changing when exit my inventory setup

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

  • I don't really use Harlowe that much, so take this with a grain of salt. That said, this is more of a design issue than a straight-forward code bug, so I think I can say something about it from that angle.

    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,
    (set: $chapter to 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:
    (set: $strength to it + 1)
    

    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:
    ::passage1
    There's a monster!
    
    [[Fight the monster!->passage2]]
    
    ::passage2
    You feel stronger now!
    (set: $strength to it + 1)
    

    You probably want something like:
    ::passage1
    There's a monster!
    
    (link: "Fight the monster!")[(set: $strength to it + 1)(goto: "passage2")]
    
    ::passage2
    You feel stronger now!
    

    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.]
  • Awesome thanks for the help! didnt even think off addding it to the link, organizes it a bit better that way anyways. Greatly appreciated!
Sign In or Register to comment.