Howdy, Stranger!

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

[SugarCube] actions macro eliminiates all links to the same passage

Took me a bit to figure out why all my links were disappearing:

I'm using the <<actions>> macro to give different actions (set with a variable) to use in another passage, like so:
<<actions [["Method 1 - Shake"|Experiment][$method to "shake"]] [["Method 2 - Stir"|Experiment][$method to "stir"]]>>

This lets me click on one of the actions once, but then all other actions with the same passage destination also disappear. Is there a better way to do this? Or is this just a bug in SugarCube?

(tested with SugarCube 2 in both Twine 1 and 2)

Comments

  • You should always state the story format you're using and its full version, because advice will tend to vary based on that information.


    You're using the <<actions>> macro incorrectly. It disables links based on the passage to which they go. Thus, since all of your actions go to the same passage, they all get disabled.

    You'll probably want to do something like the following:
    :: Experiment Actions
    <<actions [[Method 1 - Shake]] [[Method 2 - Stir]]>>
    
    
    :: Experiment
    Experiment intro text and code here.
    
    <<include "Experiment Actions">>
    
    
    :: Method 1 - Shake
    Shaking text and code here.
    
    <<include "Experiment Actions">>
    
    
    :: Method 2 - Stir
    Stirring text and code here.
    
    <<include "Experiment Actions">>
    


    Alternatively, you could do something like the following:
    → Using <<link>> macros.
    * <<if $expShook>>Method 1 - Shake<<else>><<link [[Method 1 - Shake|Experiment]]>><<set $expShook to true>><</link>><</if>>
    * <<if $expStirred>>Method 2 - Stir<<else>><<link [[Method 2 - Stir|Experiment]]>><<set $expStirred to true>><</link>><</if>>
    
    → Using setter links.
    * <<if $expShook>>Method 1 - Shake<<else>>[[Method 1 - Shake|Experiment][$expShook to true]]<</if>>
    * <<if $expStirred>>Method 2 - Stir<<else>>[[Method 2 - Stir|Experiment][$expStirred to true]]<</if>>
    
  • Thanks for the reply!

    I guess I should have been more clear: my requirements are that each action can only be taken once, and that the order of them needs to be remembered (I was adding the current $method to an array at the Experiment passage).

    My first fix was something like your first example (only with setter links), but the dummy "Method 1 - Shake" passages were just <<include "Experiment">>.

    I didn't like that, so I ended up making a macro based off your second example, only using linkreplace instead as a sorta-janky way to automatically remove the option after it's selected.
    → "try" widget: displays a one-time-click option (and an optional passage destination)
    <<widget "try">><<if $args[0]>>\
    <<if not $triedmethods.includes($args[0])>>\
    <<linkreplace `"- " + $args[0]`>>\
    <<set $method to $args[0]>>\
    <<set $triedmethods.push($method)>>\
    <<if $args[1]>><<goto $args[1]>><</if>>\
    <</linkreplace>>\
    <</if>>\
    <</if>><</widget>>\
    
    → Experiment actions:
    <<try "Shake" "Explosion">>
    <<try "Stir" "Experiment">>
    <<try "Taste" "Experiment">>
    <<try "Stare it down.">>
    

    This initially ran into the problem that <<linkreplace>> resets each time you visit a page, unlike <<actions>> --- so I made it so the attempted method is added to $triedmethods, and it filters out methods previously attempted. This also automatically filled my second requirement of tracking the order of things.

    This isn't a perfect solution, since it globally disallows repeat methods, but it'll have to do. If anybody else uses this, you'll probably want to rename the variables to suit your needs (here, $method tracks the most recent click and $triedmethods has all of them).

    Still frustrated that all of this this is to do how it seems <<actions>> should work in the first place -- eliminate per entry, not destination. C'est la vie...

    ( Versions: Twine 1.42 and SugarCube 2.16.0 )



Sign In or Register to comment.