Howdy, Stranger!

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

How can I implement cycling text options linked to variables?

Can somebody please explain to me how I can enable a player to cycle through different possible text options that each set different variables which come into effect on moving to the next passage?

So you might have for instance:

You drink the purple splooge.

...but on clicking 'purple' it then turns to the word 'green', click it again 'pink', again and it goes back to 'purple' and which ever option the player leaves it on when they move to the next passage it will enable the respective variable.

Comments

  • Many use Furkle Industries's "Cycling Links" script to achieve this result.

    You only need to use two of his three examples:

    1. The example titled Insert into passage which goes into your passage.

    You will need to edit the name (all occurrences) of the $myVar variable as well as the text options contained with the data-cycling-texts array.

    2. The example titled Insert into Story JavaScript (minified): which goes into your Story Javascript area.
  • edited June 2016
    Sorry, I'm still having trouble.

    To clarify, I'm using Twine 1 with sugarcane and this script says harlowe.

    Here's what I tried:
    <<set $sc to "Purple">>
    
    You drink the <mark><tw-link class='cyclingLink' data-cycling-texts='["Purple", "Green", "Pink"]' onclick='clickCyclingLink(this, "$sc");'><<print $sc>></tw-link></mark> splooge.
    
    [[a]]
    

    ...and I opened a new script passage, tagged it harlowe and pasted -
    function clickCyclingLink(e,a){var t=JSON.parse($(e).attr("data-cycling-texts"));if(!("undefined"==typeof t||t.length<2)){t.push(t.shift());var i=t[0];if("$"===i[0])i=getHarloweVariable(i);else if("out"===i)$(e).remove();else if("end"===i){var n=t[t.length-1];t="$"===n[0]?[getHarloweVariable(n)]:[t[t.length-1]],$(e).hasClass("endedCyclingLink")||$(e).addClass("endedCyclingLink")}else if("goto "===i.slice(0,5)){var l=i.slice(5,i.length);"$"===l[0]&&(l=l.slice(1,l.length));var s=parseInt(l.trim());if(isNaN(s)){var r=$("tw-storydata > tw-passagedata[name="+l+"]");"undefined"!=typeof r&&r.length>=1&&_engine.goToPassage($(r).attr("pid"))}else{var r=$("tw-storydata > tw-passagedata[pid="+s+"]");"undefined"!=typeof r&&r.length>1&&_engine.goToPassage(s)}}setHarloweVariable(a,t[0]),$(e).text(i),$(e).attr("data-cycling-texts",JSON.stringify(t))}}function getHarloweVariable(e){return"undefined"!=typeof e&&""!==e?"$"===e[0]?_state.variables[e.slice(1,e.length)]:_state.variables[e]:void 0}function setHarloweVariable(e,a){"undefined"!=typeof e&&""!==e&&"undefined"!=typeof a&&("$"===e[0]&&(e=e.slice(1,e.length)),_state.variables[e]=a)}var _engine=Engine;window._engine=_engine;var _state=State;window._state=_state,window.clickCyclingLink=clickCyclingLink,window.getHarloweVariable=getHarloweVariable,window.setHarloweVariable=setHarloweVariable;
    

    Should that work if I'm using sugarcane?

    The error messages I get are
    You drink the HTML tag 'tw' wasn't closed.Purple splooge.
    which it I think it should be as it includes a
    </tw-link>
    

    and on the next passage titled 'a' it reads -
    You drank the <<print>> bad expression: $sc"" splooge.

    What am I doing wrong?

    I noticed there are three examples headed 'Insert into Story JavaScript (minified)'

    Am I using the wrong one?
  • I'm sorry but for some reason I gave you a solution for Harlowe, I must of been not fully all there earlier. The following solution is for Sugarcane.

    Visit this Glorious Train Wrecks link and copy the code from the section titled Script code into your story's script tagged passage, the code will add a cyclinglink macro to your story.

    If you don't have a script tagged passage then use the Story -> New -> Script menu items to create one.

    The following example shows how to use the new cyclinglink macro with a $colour variable that stores the currently shown option.
    <<set $colour to "purple">>\
    \
    So you might have for instance:
    
    You drink the <<cyclinglink $colour "purple" "green" "pink">> splooge.
    
  • I DRANK THE GREEN SPLOOGE! Yess! Thank you once again greyelf! I'm chuffed.
Sign In or Register to comment.