SugarCube load game in passage?

I'm just wondering if it's possible to put SugarCube's load game as a button link in a passage instead of the UI?

This is for having a proper title screen with a centered passage containing start and load buttons. The load button would basically function the same as the ui load link.

Comments

  • Put this in your JavaScript:
    $(document).on("click", "a#trigger", function(){
    $("#menu-saves a").trigger("click");
    });
    And this in a passage:
    <a id="trigger">open save game</a>
    This should work in both SugarCube 1.x and 2.x, on either Twine 1 or 2. (Assuming nothing changes between now and the SugarCube 2.0 release.)
  • Thank you!
  • Hmmm, any easy way to get the link to appear as a button?
  • I'd probably just CSS it. :) http://css3buttongenerator.com/

    But if you want it an actual button:
    <button type="button" id="trigger">Button.</button>
  • I came across my own solution while you were writing that, using the SugarCube macro:

    <a id="trigger"><<button "Load Game">>Load Game<</button>></a>
  • Huh, I didn't know you could do that.

    http://stackoverflow.com/questions/6393827/can-i-nest-a-button-element-inside-an-a-using-html5
    But that said, while it certainly worked in everything I just tried it in, it's not formally allowed, and this page raises a good point, that even <button> on its own really should be wrapped in <form>.

    Again though, it DOES work, and probably will continue to do so, so while it might not be best practice... :)
  • Please, just use the API.  For example:
    <<button "Load Game">><<script>>UISystem.saves()<</script>><</button>>

    nicolem wrote:

    and this page raises a good point, that even <button> on its own really should be wrapped in <form>.


    Not unless it's part of an actual &lt;form&gt;.  The suggestion on that overflow to use a &lt;form&gt; to make a &lt;button&gt; act like an &lt;a href=&gt; is daft (the proper answer would have been something like &lt;button onclick=&quot;location.href=&#039;http://example.com/&#039;&quot;&gt;Visit Website&lt;/button&gt;).
  • Ok. :P

    I looked at the API, just didn't know you could do that. Thanks! :)
  • Every method under Built-ins in the UISystem API document opens one of the built-in dialogs (see: UISystem.saves()).
  • Yeah, I was looking under the Save System API, not the UI API. If I had looked in the right place probably would have found the answer before opening this topic.
  • It's not a problem (and without knowing any better, looking under SaveSystem wasn't a crazy idea, just not the right place as it turns out).  I just didn't want you using a Rube Goldberg machine for something which has simple solution.