Howdy, Stranger!

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

How to forbid an (if:) to repeat in a loop, once it has been displayed once ?

Hey again !
I'm still trying to figure out how to do stuff, and I can't find a good way to do what I want...
I'm on Harlowe 2.0 and Twine 2.1.0

Alright, so here is the thing, I'm trying to do a loop which will return to

every once in a while.

When it does, I'd like Harlowe to check what is new to the story, thanks to variables (when stuff happens, I create a variable named $StuffA, and give it the value 1)

That way, I can do, inside Room
(if: $StuffA is 1)[Oh you did this !]

The thing is, once the program has said to you that you did StuffA once, you don't really want to hear about it again.
So I thought about doing :
(if: $StuffA is 1 and $said is 0)[Oh, you did this ! (set: $said to 1)]

It would work that way, I guess. But it implies for me to create a new variable $said, for each event that occurs in my story, which isn't convenient.

Does anyone know of a better way ?...

Thanks a lot !


  • You can just increment $StuffA again:
    (if: $StuffA is 1)[Oh you did this! (set: $StuffA to $StuffA + 1)]

    I'm not sure where the loop part is, though.
  • I can't increment $StuffA as I'll use its value in the future, in order for other events to occur.

    Well, I'm calling a loop the fact to go back again and again to the room. I'm sorry if I'm not expressing myself correctly, I am not english :(

    Another issue I have : Even when the "(if:) is false, and doesn't appear, it takes place within the screen.

    Like this : 762221erroor.png

    In my code, there are two (if:) above "Contact someone" and "Look up your info". When you play, you don't see them, but they take place anyway.

    Thanks for your help !
  • If you can't increment $StuffA, then I think using another variable will be the easiest way. As far as the space on screen, you can use the line continuation markup, which is "\".

    (if: $StuffA is 1)[Hello!
    More Stuff.

    The above code will output:
    More Stuff.
    If $StuffA is 1 and
    More Stuff.
    with no leading white space or line breaks if $StuffA is not 1.

    You'll need to include line breaks in the hook in you want line breaks in the output. NOTE that line breaks inside hooks only work in Harlowe 2.x, not in Harlowe 1.x.
  • You could use an Array to track which messages have been seen by added an unique identifier to the array for each one that is, and then check that the array does not contain a specific identifier for each conditional statement. (eg (if:) or (else-if) macro)

    1. Initialize the empty array and any other variables within your startup tagged Passage.
    (set: $seen to (array:))
    (set: $stuffA to 1)

    2. Test for the message and identifier in your Room Passage.
    <!-- the printing of the $stuffA variable can be removed, it is only used for testing. -->
    stuffA: $stuffA
    (if: $stuffA is 1 and not ($seen contains "StuffA1"))[
    	(set: $seen to it + (array: "StuffA1"))
    	You did stuff A.
    (else-if: $stuffA is 2 and not ($seen contains "StuffA2"))[
    	(set: $seen to it + (array: "StuffA2"))
    	You did stuff B.
    	<!-- this (else:) can be removed, it is only used for testing. -->
    	(set: $stuffA to it + 1)
    	(if: $stuffA > 2)[(set: $stuffA to 1)]
    note: You can rename the $seen variable to whatever makes sense to your store, you can also change the String identifier values being stored within the array to something more meaningful to you.
  • Thanks, both of you ! It works perfectly, I'm going back to work :smile:
Sign In or Register to comment.