Howdy, Stranger!

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

(Harlowe) Back to previous passage macro for my battle system

In my battle system, I want to create a boss that needs certain requirement (e.g. Strength) to be met before player is allowed to encounter him. If player does not meet such requirement, they will be given a warning pop-up box to say something like "your strength does not meet 150" then after clicking OK, the player is automatically taken back to the passage which they came from.
(if: $jobclass is $Berserker and $Strength < 150)[
          (set: $prompt to (confirm: "You do not have enough Strength (150) to face this opponent"))]
          (if: $prompt is true).......
]

(note: the "......." just means I don't know what to write after that)

I've read up on some of the replies from this post "https://twinery.org/forum/discussion/2910/back-or-return-in-harlowe"; and did some more research on forum, but I do not seem to have found an answer to my problem.
If I want to be able to go to this passage which I called Passage "Sir. Oxóssi Mixcoatl", from Passage A, B, C & D, is there a macro which could determine which passage I came from and returns me to that passage automatically?

Attached is a picture of my story map, hope it helps clarify the problem a bit.

Thank you.

Comments

  • The 'last' element of the array returned by the (history:) macro contains the name of the previous passage, you can combine that with a (go-to: ) macro to more the Reader forward to the previous passage.
    (go-to:  (history:)'s last)
    

    Why do you need to assign the return value of the (confirm:) dialog to a variables when you are always going to send the Reader to the previous passage if they are a $Berserker with a $Strength < 150?
    You could simplify the code to:
    (if: $jobclass is $Berserker and $Strength < 150)[
    	(confirm: "You do not have enough Strength (150) to face this opponent")
    	(go-to:  (history:)'s last)
    ]
    

    Harlowe does not have a macro equivalent to SugarCube's <<back>> macro (which winds back history), although you can simulate the same effect by using Javascript to send a click event to the Undo link.
    <script>$("tw-icon.undo").trigger("click");</script>
    
  • edited July 2016
    Dear Master Greyelf, thank you for the detailed explanation.
    I've worked out the logic for the (history:) macro now, but I am still confused by the Javascript macro.

    What I am confused about, is that when I tried testing what the macro does by simply copying and pasting what you wrote into the Story Javascript Sheet, the error in the attached picture comes up whenever I tried testing the game starting from any passage.

    So would I be right to assume that I am missing a Javascript code which will tell the
    <script>$("tw-icon.undo").trigger("click");</script>
    
    to be linked to an Undo icon/button which I've to create within a certain passage?
  • You originally asked how to conditionally go to the previous passage from the current passage, and both my answers are about doing that.

    1. To go forward to the previous passage you would use the (go-to:) macro within the associated hook of the (if:) macro.

    2. To undo history and go back to the previous passage you would replace the line containing the (go-to:) macro with the <script> example code.
  • A cleaner design would be to not allow navigation to the "Sir. Oxóssi Mixcoatl" passage. You can simply put a conditional link like (if:$strength >= 150)[{link}](else:)[Your strength isn't high enough to challenge the mighty Sir. Oxóssi Mixcoatl.]

    Dear god that name though...
  • Hi Lily, thanks for the input :smiley:
    I will consider on your suggestion and see if I could make it a cleaner design :smile:

    About the name, yeah it's quite long and probably hard to pronounce, but I did find it hilarious when I combined the 2 hunter gods together :blush:
  • Is it possible to grey out the link to "Sir. Oxóssi Mixcoatl", therefore it is still showing the link but nothing happens when you click on it, and only make it clickable when player reaches say a Strength of 150?

    If so, how would I build the code?
  • mitholas wrote: »
    Is it possible to grey out the link ...
    Yes, it is possible to use a combination of Javascript and CSS to disable a link so that it is un-clickable and changes colour, but disabling may not always work or look correct depending on operating system and web-browser used by the reader.

    You could just use code like the following to show either a real link or a fake link depending on a condition.
    (if: $Strength < 150)[<span class="fake-link">Link Text</span>](else:)[ [[Link Text->Target Passage]]]
    
    ... and use CSS like the following (which is based on Harlowe defaults) to style the fake link:
    .fake-link {
        color: grey;
        font-weight: bold;
    }
    
Sign In or Register to comment.