Howdy, Stranger!

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

Change passage automatically?

I am new to Twine 2 and I have a, what I think a great idea of an adventure. :)

But I have ran into a problem... one passage makes a move to a new one based on what numer is randomly picked.
How do I do that?

(if: random(0,9) > 4) is my guess... no idea if am even close to the solution.

Comments

  • Welcome to Twine 2!

    When you start using Twine 2, by default you are using a style called "Harlowe," this determines the syntax for links and functions and everything you can do. So I'm going to talk about how to do things in Harlowe, which is almost certainly what you're using. (This will matter if you encounter a problem, because the answer will be different for Harlowe than for some other style)

    There's a lot of information about what you can do in Harlowe at:
    http://twine2.neocities.org/

    To answer your specific question, I understand that you're trying to pick a passage name for the user to visit randomly from two or more options. There are many different ways to do that in Harlowe, depending on the specifics of what you want to achieve. Here are a few of the simpler ones.

    You could start out by picking randomly from a set of strings that represent passage names. You can do this using (either:).
    (either:"passage name","other passage name","third passage name")
    In this way, you can easily select one of several strings. They don't have to be passage names - for what you're trying to do, they would be, but you could also just say
    The sky is (either:"blue","starlit","cloudy").
    You can put as many strings as you want. In your case you'd want to put in the passage names you want to choose from, and then use the result in your passage link.

    The limitation of (either:) is that you will have equal chances of getting any option. Maybe you want to have a greater chance of getting one option tan another. In that case, you can do it as you suggested and use random number generation. The syntax for random in twine 2 is
    (random: 0,9)
    and you correctly guessed that you can use
    (if: (random:0,9) > 4)
    to check if your random number between 0 and 9 is greater than 4.

    If you want the user to click text to go to another passage, a simple ways to do it is a [[passage link]] like in twine 1. If you don't want to display the text of the passage name as the passage link, you can use [[text to display->name of passage to visit]].

    So for example, try:
    You are lost in a maze. Ahead, the corridor ends at [[(either: "an empty room","a dead end","a T-junction")]]
    where "an empty room", "a dead end", and "a T-junction' are passage names

    or:
    You are lost in a maze. Ahead, the corridor ends at [[a swirling mist->(either: "an empty room","a dead end","a T-junction")]]
    which would always display "a swirling mist" as the link, but would take you to one of those three passages.

    or:
    {
    (set: $destination to "First Destination")
    (if: (random:0,9) > 6)[(set: $destination to "Second Destination")]
    }

    You are lost in a maze. Ahead, the corridor ends in [[a swirling mist->$destination]]
    which will take you to "first destination" 7/10 of the time, "second destination" the rest. (The {}s prevent the code in between them from generating a bunch of superfluous newlines in your passage)

    If you want to go beyond [[links]],
    (display:"my passage")
    will display the text of the passage named "my passage" inside your current passage, wherever you put the
    (display:)
    command. You can use hooks and (click:) and (replace:) to display text in specific places when the user clicks something. There are too many options to go into detail here :) But I hope that gives you an idea of some possibilities.
  • Wow! Thank you! I haven't read everything yet but my sixth sense says that the answer is in there! :)
  • I am a newbie, trying to get 2.x to work for me. Oakandsage's response above, this part

    You are lost in a maze. Ahead, the corridor ends at [[a swirling mist->(either: "an empty room","a dead end","a T-junction")]]

    which would always display "a swirling mist" as the link, but would take you to one of those three passages.


    is what I'm after, but it doesn't seem to work for me. I want the display text to remain the same, but the link shifts. Anyone know why it's not working?

    I'm using Chrome, btw.
  • Geocam, are you using Harlowe? If you're using another story formatter, the syntax will be different.

    For instance, in Sugarcube:
    [[a swirling mist|either("an empty room","a dead end","a T-junction")]]
  • Sorry. I should have identified Harlowe. Yes, nicolem, it's Harlowe. I've tried variations, some informed (like |) some randomly (extra space, etc.) . Can't figure out where the problem is.
  • Okay, just making sure! :)

    What happens when you click the link? Does it appear to always go to the same passage? Try clicking it 30 times.

    Failing that, are you 100% sure that the EXACT title of all three of your passages corresponds to what's in the either() function?

    And finally, if that still doesn't work, can you post your link here?
  • Lordy, lordy, nicolem! Thanks. Clicking toward 30 worked. But it left me with another question: Why don't the links show up on the story map?
  • Heh, you can tell I've been burned by one of those bugs recently, huh? Glad I could help!

    But yeah, there's a reason they're called PSEUDO-random number generators. ;)

    As for the story map passage links themselves, I think it's just a limitation of Twine 2's parsing method: it's looking for a passage named either("1","2","3"), not three passages named "1", "2", and "3". I THINK the story map renderer is independent of story formatter, so it might be something worth submitting a ticket over. That said, the actual syntax of the passage link either() function differs, so there might not be a one-solution-fits-all way for Twine itself to accommodate it.
  • nicolem wrote:

    Heh, you can tell I've been burned by one of those bugs recently, huh? Glad I could help!

    But yeah, there's a reason they're called PSEUDO-random number generators. ;)



    I don't like using random generators without checks against this sort of thing. So I always use variables to do something like:

    1. Roll once
    2. Set variable equal to result
    3. Roll again next time function is triggered
    4. If result is same as variable, add 1 to roll

    That way it's literally impossible to get two of the same number in a row, because the previous roll is removed from the pool. Which is not entirely random in itself, but feels more "random" to an observer.
  • nicolem wrote:

    As for the story map passage links themselves, I think it's just a limitation of Twine 2's parsing method: it's looking for a passage named either("1","2","3"), not three passages named "1", "2", and "3". I THINK the story map renderer is independent of story formatter, so it might be something worth submitting a ticket over. That said, the actual syntax of the passage link either() function differs, so there might not be a one-solution-fits-all way for Twine itself to accommodate it.

    You are correct about the limitation.

    Due to each of the existing (and any future new) story formats having their own definition of what exactly is a link (both markup based and macros) the Twine 2 application currently can get it wrong when auto-creating a new passage and when drawing arrows between passages on the Story Map.

    Once each story format is able to tell the application what can constitute a link these problems should go away or at least reduce, though links where the target passage name is contained in a variable will probably still be an issue because there is no way to know what value the variable will contain unless you play the story.
  • I like the idea of the swirling mist, but if it doesn't give you rooms on the map. how can I put content in them?
  • Sage wrote:

    I like the idea of the swirling mist, but if it doesn't give you rooms on the map. how can I put content in them?


    i think you can add those passage manually by clicking the green button in bottom right corner and give a name exactly as the random items.
Sign In or Register to comment.