Howdy, Stranger!

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

inserting content from variable multiple times

Guys, in my quest to conquer Twine I'm wondering if you have ideas about the following. I'll first describe what I want, then my idea of a solution and where I'm stumped, and then hopefully you can solve my issue or even improve upon it.

What I want is:
- Dialogue with interactive moments
- Happening on a single page
- Upon making a choice the next segment of written content loads
- Dialogue occurs while characters walk through a chosen path (lets call them left, right, middle and up path)
- The paths have separate descriptions I insert in between the dialogue

So an example:
Which path do we take? Left, right, middle or up?
(player chooses middle)
Dialogue section 1
Middle path description 1
Dialogue section 2
Middle path description 2
Etc

I've solved displaying previously hidden divs upon making a choice with some forum help, so I can do parts of the story without using passages. What I can't seem to solve is how to use a variable upon selection that I +1 for the description pieces I draw from variables. Kind of like:

<<set $route_choice = "middle_description_01">>
<<print $middle_description_01>>
now how do I set $middle_description_01 to middle_description_02 at the end of that print statement?

Hope this makes some sense, if more info is needed let me know. If there are better ways to do this I'm all ears, but I'd like to avoid huge if else statements.

Using Twine 2 desktop and Sugarcube 2.

Comments

  • If you want your story to be displayed on a single page then I would suggest installing Twine 1.x and using the Jonah story format, it is designed to work that way.

    I must admit I may not be totally understanding your question but if you want to change the value stored in a particular variable after you display it then you just assign the variable a different value.
    <<set $route_choice = "middle_description_01">>
    <<print $middle_description_01>>
    <<set $middle_description_01 = "the different value">>
    
  • I really want to stick to sugarcube because of the save feature, otherwise the Jonah format sounds really good (hadn't heard of it before).

    I think I may have explained myself a bit poorly and also made a logic error surrounding variables. Let me try again because I'm pretty sure if you follow my ramblings you'll have an answer for me ;)

    I write environment details for multiple options. Something like:

    $route_left_01 = "The left road is made of marble so deeply polished you can see your reflection"
    $route_left_02 = "As you progress on the road the shine becomes less and less however"
    $route_left_03 = "eventually the once radiant trail doesn't resemble marble at all..."

    I do the same for the middle and right roads and display these variable descriptions depending on what the player chose. Maybe that explains it a bit better?

    Now what I'm stumped at is how intelligently work this into the code without a crapload of if else statements. Is there anything which comes to mind?
  • note:
    From your original description it sounds like you are using variables to make a single Passage behave as if it is actually multiple passages by dynamically changing what section of the single Passage is being shown without the Reader moving from one Passage to another.

    If this is true then you may want to test that the save/load feature works correctly for you because I believe it is designed to remember which Passage the Reader last saw, which Passages the Reader traveled through to get to the current Passage, and what values each of the variables had for each of the Passages seen.
    There may be an issue with what section of your "a single Passage behave as if it is actually multiple passages" passage is actually displayed to the Reader if they re-load a story that was saved while displaying that Passage.

    To answer your question about variables

    Instead of using an unique variable for each of your $route_left_01, $route_left_02, and $route_left_03, you could instead use a Javascript array to store each of the left paths and then use an index variable to determine which is shown.

    Place the following variables in your StoryInit special passage:
    /% Array where each element is one of the route left descriptions. %/
    <<set $routeLeft to [
    "The left road is made of marble so deeply polished you can see your reflection",
    "As you progress on the road the shine becomes less and less however",
    "eventually the once radiant trail doesn't resemble marble at all..."
    ]>>
    
    /% Index of which $routeLeft element to show, first element is zero, last element is (number_of_elements_in_array - 1) %/
    <<set $left to 0>>
    
    ... place the following in a passage, it shows how to show one $routeLeft value and then another by changing the $left index variable:
    <<print $routeLeft[$left]>>
    
    <<set $left to 2>>
    <<print $routeLeft[$left]>>
    
    Now instead of using <<if>> macros you just need to set $left to the correct number.


    You and use the same technique to handle both left and right at the same time by using a multidimensional array like the following.
    StoryInit:
    <<set $routes to [
    [
    "The left road is made of marble so deeply polished you can see your reflection",
    "As you progress on the road the shine becomes less and less however",
    "eventually the once radiant trail doesn't resemble marble at all..."
    ],
    [
    "the first right description",
    "the second right description",
    "the third right description"
    ]
    ]>>
    
    /% the directtion the Reader is traveling, zero is left, one is right. %/
    <<set $direction to 0>>
    
    /% which path within a direction to show. %/
    <<set $path to 1>>
    
    ... in a passage:
    <<print $routes[$direction][$path]>>
    
    <<set $direction to 1>> /% going right %/
    <<set $path to 0>>
    <<print $routes[$direction][$path]>>
    
  • Thanks a million. I won't have time to test it until tomorrow but this sounds exactly right. I'll also keep your comment on the save/load feature in mind :)
Sign In or Register to comment.