Howdy, Stranger!

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

[Sugarcube] How to go back twice with the history controls?

I'm wondering if there is any way to make the back function in the top left of the sugarcube ui go back 2 passages instead of 1.

Comments

  • Why would you want to do that? I'm asking, since it seems likely that this is an attempt to solve some issue you're having.

    TL;DR: What you're asking for is bizarre. So, yeah, details please.
  • edited August 2016
    Basically with some things I send the player to a check page, so for example if they go to buy a sword they are sent to a redirect page.
    <<if $gold gte 500>><<goto buysword>>
    
    <<elseif $gold lt 500>><<goto buyfail>>
    
    <</if>>
    

    The only alternative I can think of is to have an <<if>> statement on the shop page that shows one option if you have enough gold and another if you don't, but I'd really rather not do that.

    Also for some thing it does a secret check at random intervals. So it would check if strength is gte an amount and if it is you get a special event.
  • ConerNSFW wrote: »
    Basically with some things I send the player to a check page, so for example if they go to buy a sword they are sent to a redirect page.

    […]

    The only alternative I can think of is to have an <<if>> statement on the shop page that shows one option if you have enough gold and another if you don't, but I'd really rather not do that.
    As a general rule, you should avoid routing passages—i.e. passages whose only purpose is to send the player somewhere else. You should also avoid the <<goto>> macro as much as possible—i.e. use it only after exhausting all reasonable avenues first.

    Using the <<display>> macro should accomplish what want:
    <<if $gold gte 500>><<display "buysword">><<else>><<display "buyfail">><</if>>
    
    n.b. Your <<elseif>> is superfluous, an <<else>> is sufficient in this case.

    That said, a better method would be to make the originating link—the one that currently leads to the routing passage—a <<click>> macro. Then instead of using a routing passage at all, you'd place its logic inside the <<click>>:
    <<click "Buy sword">>
    
    <<if $gold gte 500>>
    	<<goto "buysword">>
    <<else>>
    	<<goto "buyfail">>
    <</if>>
    
    <</click>>
    
    That's one of the good uses of <<goto>>.

    ConerNSFW wrote: »
    Also for some thing it does a secret check at random intervals. So it would check if strength is gte an amount and if it is you get a special event.
    That could be handled with either a <<click>> macro—similar to my example above—or a routing function.

    A <<click>> example:
    <<click "Head to the village round">>
    
    <<if $strength gte 20 and random(5) is 0>>
    	<<goto "random strength event">>
    <<else>>
    	<<goto "village round">>
    <</if>>
    
    <</click>>
    
    You could even make a widget out of the event logic, if you needed to reuse it in several places.

    A routing function example:
    [[Head to the village round|route("village round")]]
    
    Obviously, you'd have to be able to write the routing function, so if JavaScript isn't your thing, you're probably be better off using something like the <<click>> example above.

    Beyond the two mentioned here, there are other ways to handle that sort of thing.
  • Thanks for the reply, I'll try it out later tonight.
  • I tried it out and it works exactly how you said it would. There are some downsides to doing it this way but I definitely think it works better than the alternative. Thanks.
Sign In or Register to comment.