Howdy, Stranger!

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

How to make a conditional link?

This is what I want (Sugarcube syntax):
<<if $oven[5]>><<301>><<else>><<35>><<endif>>
where 301 and 35 are passage titles, where I need to go depending on the $oven[5] value.
The resulting html DOES what I want, BUT displays it as if there were an error! It says: "This passage does not exist: " and then shows correctly the "non-existing" passage, all on pink background. How to fix this? (Surely I can write <<if $oven[5]>>301<<else>>35<<endif>>, but this is ugly.)

Comments

  • edited February 2016
    You've got three options I know of, and none of them are very pretty. You've found the simplest one:
    <<if $oven[5]>>[[Open oven No. 6|301]]<<else>>[[Open oven No. 6|35]]<<endif>>
    
    ...the others are..
    <<print "[[Open oven No. 6 |">><<if $oven[5]>><<print "301">><<else>><<print "35">><<endif>><<print "]]">>
    
    <<if $oven[5]>><<set $sixdest to "301">><<else>><<set $sixdest to "35">><<endif>>
    [[Open oven No.6|$sixdest]]
    

    As you're in sugarcube, you have a goto macro, so you could use a ninja link -
    [[Open oven No. 6|35]]
    

    Then at the start of 35:
    <<if $oven[5]>><<goto 301>><<else>>\
    ...rest of 35...
    <<endif>>
    

    ...but that's Spagetti code and messes the visual links in the editor up.
  • Two other ways I can think of are:
    <<set $next to "35">>
    <<if $oven[5]>><<set $next to "301">><<endif>>
    [[Open oven No. 6|$next]]
    
    and
    
    <<click "Open oven No. 6">>
    	<<if $oven[5]>><<goto "301">><<else>><<goto "35">><<endif>>
    <</click>>
    
  • The print version doesn't work, it just prints the line "Open oven No. 6 |35]]" without making a clickable link.
    Also, <<goto>> is not recognizes (No macro or passage called "goto"). I downloaded sugarcube-2 archive and unzipped it to Twine folder, keeping the names intact - what else should I do to make it work?
  • yun wrote: »
    The print version doesn't work, it just prints the line "Open oven No. 6 |35]]" without making a clickable link.
    It won't, the example is unworkable as written.

    yun wrote: »
    Also, <<goto>> is not recognizes (No macro or passage called "goto").
    If <<goto>> wasn't recognized, then you were/are probably using Sugarcane (one of the Twine 1 vanilla story formats), not SugarCube (1 or 2).

    yun wrote: »
    I downloaded sugarcube-2 archive and unzipped it to Twine folder, keeping the names intact - what else should I do to make it work?
    If you've placed the SugarCube 2 install in the correct place (the sugarcube-2 directory from the archive goes in the targets directory). All you need to do is set it as your project's story format (Story menu > Story Format > Sugarcube-2). After doing so, mykael's second suggestion and both of greyelf's suggestions should work (so should mykael's third, but don't do that, it's daft).

    If you're not afraid of a little JavaScript, you could also use the conditional/ternary operator to shorten it, like so (though, it only works for two values):
    <<set $sixdest to $oven[5] ? "301" : "35">>
    [[Open oven No.6|$sixdest]]
    


    That said, while I certainly don't recommend the vanilla story formats, to get mykael's second suggestion working in them, you'd use the following instead: (does not work in SugarCube)
    <<if $oven[5]>><<set $sixdest to "301">><<else>><<set $sixdest to "35">><<endif>>
    [[Open oven No.6|<<$sixdest>>]]
    
  • Yes, it was Sugarcane (what a stupid idea to use confusingly similar names!) And I had to reload Twine to make Sugarcube available. However, switching to it created more problems, like 14 stopped working. I'll better stay with Sugarcane then.
    Is there any way to make a delay for N seconds in this format? I guess it requires JavaScript, but how exactly to do it?
  • Persevere with SugarCube. It's worth working your way around its little differences because it can do so much more than Sugarcane - including macros for delaying things for a few seconds...
Sign In or Register to comment.