Howdy, Stranger!

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

Images that are Links that are Variables.

Ok, I'm in the home straight of my latest Twine and I've hit a conundrum.

I've used a variable to make it so that what looks like the same link will go to different passages depending on how many times the player has clicked it before. It looks like this:
<<if $timesLooked==0>>[[LOOK|look1][$timesLooked=1]]<<endif>> <<if $timesLooked==1>>[[LOOK|look2][$timesLooked=2]]<<endif>> <<if $timesLooked>=2>>[[LOOK|look3][$timesLooked=3]]<<endif>>

Which is, fine.

EXCEPT!

my links don't look like...
[[LOOK|look1]
[[LOOK|look2]
[[LOOK|look3]

...they look like...
[img[LOOK][look1]]
[img[LOOK][look2]]
[img[LOOK][look3]]

...because I'm using images to create navigation buttons, but I'm having trouble inserting that into the variable, it (or I) gets confused over which brackets are opening and closing what and wont work. Anyone know how I need to type this?

I'm using sugarcane btw.

Comments

  • For clarity...
    <<if $timesLooked==0>>[[img[LOOK]look1][$timesLooked=1]]<<endif>>
    

    ...causes the creation of a passage link which reads "img[LOOK]look1" rather than showing the LOOK image.

    All other combinations I've tried so far just seem to make it display as black text (indicating it won't do anything other than display on the page).
  • The format should be:
    [img[LOOK][look1][$timesLooked=1]]
    
    ... but Sugarcane does not seem to support it although SugarCube does.

    It appears that in Sugarcane you can either have an Image Link or a Setter Link but not both, but you can get around the issue by wrapping the image in a HTML hyper-link like the following:
    <<if $timesLooked==0>><a data-passage="look1" data-setter="$timesLooked=1">[img[LOOK]]</a>\
    <<elseif $timesLooked==1>><a data-passage="look2" data-setter="$timesLooked=2">[img[LOOK]]</a>\
    <<elseif $timesLooked>=2>><a data-passage="look3" data-setter="$timesLooked=3">[img[LOOK]]</a><<endif>>
    
  • greyelf wrote: »
    The format should be:
    [img[LOOK][look1][$timesLooked=1]]
    
    ... but Sugarcane does not seem to support it although SugarCube does.
    You are correct—IIRC.
  • edited April 2016
    Thank's @greyelf I'll see if I can get my head around the HTML there, unfortunately my project is much too far along to switch story format now (gave it a test to see how much difference it made and it broke basically everything), but I'll definitely remember that for future projects.
  • Managed to get my head around it (thanks for giving a nice clear example there, I was able to modify it for a bunch of different passages in my story) and it's working great now. Thanks again!
  • Ok one last problem has occurred; onto this list of variables I'm trying to ad just one more as an exit for once the player has visited every location in the story.

    So...
    <<if visited ("placeA") and ("placeB") and ("placeC") and ("placeD")>>[img[EXIT]]<<endif visited>>
    

    That's how I would, and can, express it if once the player has gone everywhere a new extra button would appear beneath the main three navigation ones I'm using.

    BUT, it would be nice if rather than a new button appearing it replaced the central LOOK button in the same way I've been doing so far, but I'm not sure how to add that onto the end of the list of variables I'm using at the moment. Everything I've tried either doesn't work or throws up errors.
  • edited April 2016
    Have you tried something like this?

    <<if visited ("placeA") and ("placeB") and ("placeC") and ("placeD")>>[img[EXIT]]<<else>>link<<endif visited>>

    You could also just set a $variable once they have visited everywhere and use that instead of visited, I don't really use visited much so I'm not 100% on the syntax of <<if visited>> but above definitely works with normal if statements.
  • procrasty wrote: »
    <<if visited ("placeA") and ("placeB") and ("placeC") and ("placeD")>>[img[EXIT]]<<endif visited>>
    
    There are a couple of syntax errors in your example, it should look like the first line of the following which also shows either the Exit link or one of the Look links.
    <<if visited("placeA") and visited("placeB") and visited("placeC") and visited("placeD")>>[img[EXIT][exit]]\
    <<elseif $timesLooked==0>><a data-passage="look1" data-setter="$timesLooked=1">[img[LOOK]]</a>\
    <<elseif $timesLooked==1>><a data-passage="look2" data-setter="$timesLooked=2">[img[LOOK]]</a>\
    <<elseif $timesLooked>=2>><a data-passage="look3" data-setter="$timesLooked=3">[img[LOOK]]</a><<endif>>
    
  • If you wish to check if the player has been to all of those passages, then you may simply pass all of them to visited(). For example:
    <<if visited("placeA", "placeB", "placeC", "placeD")>> …
    
    When multiple passages are given, visited() returns the lowest count.
  • Perfect!
    Thanks everyone!

    The fruits of this should be posted in the week :D
Sign In or Register to comment.