Howdy, Stranger!

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

[SugarCube 2.7] Change and display custom variable after moving to a new passage

Hey ho,

I am currently working on a story in which I want to integrate a mood system. What I mean by that is that the main character you play is supposed to have a certain mood that changes (or stays the same) when you move to a new passage depending on what passage that it.
For Example, there could be the moods "good", "mediocre" and "bad". I like to imagine them like a rating system: "good" = 3; "mediocre" = 2 and "bad" = 1. So if the player clicks in a passage where the mood is set to "mediocre" (2) on a link which results in an increased mood value the new passage should output the mood "good". And if he chooses in this new passage a link which results in a decreased mood value the new mood should be set to "mediocre" again. This way every player could end up with different mood settings in different passages therefore customizing the experience at least on the surface.
Is there a possibility to build something like that in Twine 2 using SugarCube 2.7? I searched for tutorials which maybe do something similar, but couldn't find anything. I am new to scripting so I am not quite sure where to start.

Every hint is greatly appreciated :)


Comments

  • Personally, I'd start with the documentation.

    You could use either the <<click>> macro or, as long as your version of Twine 2 isn't ancient, setter links.

    Let's just assume for the moment that the "mood" variable is going to be an integer, which you've initialized in the StoryInit special passage like so:
    /* Start the character in a good mood. */
    <<set $mood to 3>>
    

    Here's how you might write a passage link which lowers the character's mood:
    /* Using <<click>>. */
    <<click [[Angrily storm out of the house.|Outside]]>>
    <<set $mood -= 1>>
    <</click>>
    
    /* Using a wiki link with setter (a.k.a. a setter link). */
    [[Angrily storm out of the house.|Outside][$mood -= 1]]
    

    Now, say you wanted to have something be contingent upon their mood, you might do so using <<switch>> macro or <<if>> macro:
    /* Using <<switch>>. */
    <<switch $mood>>
    <<case 3>>
    …in a good mood…
    <<case 2>>
    …in a mediocre mood…
    <<case 1>>
    …in a bad mood…
    <</switch>>
    
    /* Using <<if>>. */
    <<if $mood is 3>>
    …in a good mood…
    <<elseif $mood is 2>>
    …in a mediocre mood…
    <<elseif $mood is 1>>
    …in a bad mood…
    <</if>>
    
    /* Another using <<if>>. */
    <<if $mood lt 3>>
    …not in a good mood…
    <</if>>
    
Sign In or Register to comment.