Howdy, Stranger!

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

One-Time Variables?

I have two questions about this:

1. My beginning passage has the code:
(set: $stories_completed to 0)
When the player completes a story, I want it to return to the start passage so they can start another story, but how do I avoid the variable being set back to zero as it is in the start passage?

2. When a player finishes a story, is there a way to increment the "stories completed" variable only once so that when players complete it a second time, it doesn't just keep completing stories?

Comments

  • 1. Is there a reason you need to set that variable at the very beginning? My understanding is that a variable you haven't defined will be assumed to be blank/0.

    With that assumption, my suggestion would be not to set the variable until a player completes a story.

    So, on the last passage of any story, you could include:
    (set: $stories_completed to it+1)
    which would bump up the story count by one.

    2. If I'm understanding you correctly, you're wanting to avoid a situation where someone just completes the same story over and over, and bumps up their total that way.

    One suggestion might be to name each story, and then use an if macro to determine whether the story completed variable goes up. e.g.:
    (if: $Story1 is not true)[(set: $stories_completed to it+1)(set: $Story1 to true)]
  • You can use (history:) to determine if the player has visited the start passage before or not. It is not affected by the player using the backtrack buttons.

    The following code will solve your problem if your story begins in a passage called Begin:
    (if: (history:) contains "Begin")[(set: $played to it + 1)](else:)[(set: $played to 0)]
  • Another solution similar to st33d's, if you want to make your test independent of page names (for example, if each story has multiple ending pages), would be
    (set: $stories_completed_array to (array:))
    $stories_completed_array is an array, initially blank, that lists the name of every story the user has completed.

    Then when a user completes a story:
    (unless: $story_name is in $stories_completed_array)[(set: $stories_completed_array to it + (array:$story_name))]
    That will append the story name to the array, but only if the user hasn't completed the story.

    To find out if a user has completed $story_in_question:
    (if: $story_in_question is in $stories_completed_array)[do the appropriate thing]
    To find out how many unique stories the user has completed:
    (print: $stories_completed_array's length)
    Disclaimer: Normally I test code snippets before posting them, but I didn't today. Syntax is correct to the best of my understanding.
Sign In or Register to comment.