Howdy, Stranger!

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

How do I make a command fire only once?

I've been working with Sugarcube in Twine 2 to produce a fairly simple adventure game of branching narrative paths.

I've found that the main thing I keep running up against is the need to run a command or function only the first time the passage is read--i.e. I want a <<set>> command in the passage "Meet the wicked witch" to increment $witchesmet by 1, but I don't want it to increment again until passage "Meet the good witch," even if the player reads through "Meet the wicked witch" a second time.

I've come up with an assortment of jury-rigged hacks for this in the form of an unwieldy sequence of <<if>> and <<else>> calls, but it's getting difficult to sustain them, and I can't help but feel that I'm missing something obvious. Does anyone have any help for me?

Comments

  • Please state the version as well as the name of the story format you are using when you ask a question, as answers can be different or change between versions. I will assume you are using version 1.0.34 that comes with the application.

    One way to solve the issue is to use the visited() function to check how many times the reader has seen the Meet the wicked witch passage.
    <<if visited() < 2>><<set $witchesmet += 1>><</if>>
    
    motoslave.net/sugarcube/1/docs/utility-functions.html#functions-visited
  • That's pretty much what I was looking for, yeah. I've just found the official documentation for Sugarcube a bit dense, but hopefully I'll get the hang of it soon.

    Thank you!
Sign In or Register to comment.