Howdy, Stranger!

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

[Sugarcube] How to have pop-up menus / use UI.alert

I would like to have a pop-up window display a passage or some text or an image.

I've been reading the sugarcube documentation but it doesn't explicitly say how to use UI.alert.

Comments

  • Version of SugarCube?
  • edited October 2016
    2.10 (latest)
  • edited October 2016
    I'm away from my computer right now, however, you want the Dialog API.
  • And, I'm back. Now for a little more detail.

    I'm unsure what you're finding confusing about the UI.alert() documentation. It's really not that complicated. As the included example shows, you would normally call it simply with the message you wish to display to the player. As a silly example:
    <<button "For realzies?">>
    <<script>>
    UI.alert("Totes, yo!");
    <</script>>
    <</button>>
    

    That said. UI.alert() is meant for small text messages, similar to the browser's alert() function. If you want to display markup and images, then you want the Dialog API, which allows you to create your own modal windows containing whatever you want. A common usage is to display a passage within a modal—see: Dialog.setup() for examples.

    Here's a simple example of how to open a modal titled "Character Sheet", with the class "charsheet", containing the passage named "PC Sheet":
    <<button "You">>
    <<script>>
    Dialog.setup("Character Sheet", "charsheet");
    Dialog.wiki(Story.get("PC Sheet").processText());
    Dialog.open();
    <</script>>
    <</button>>
    

  • Thanks that was exactly what I wanted. At first I just ran the <script> and nothing happened so I assumed I wasn't meant to use the <script> function, when really I was just meant to put it inside a <<button>> or <<link>>.

  • ConerNSFW wrote: »
    Thanks that was exactly what I wanted. At first I just ran the <script> and nothing happened so I assumed I wasn't meant to use the <script> function, when really I was just meant to put it inside a <<button>> or <<link>>.
    No. I simply used <<button>> in my examples. You don't need to use it at all.

    If your post is anything to go by, then you simply used the wrong markup: <<script>> vs. <script>. The former is the script macro, which is what you should be using—and you'll note it's what I use in the examples. The latter is the HTML script tag, which is non-functional within SugarCube's markup.
  • edited October 2016

    If your post is anything to go by, then you simply used the wrong markup: <<script>> vs. <script>. The former is the script macro, which is what you should be using—and you'll note it's what I use in the examples. The latter is the HTML script tag, which is non-functional within SugarCube's markup.

    I tried it exactly as before and it still won't work without the <<button>>. I'm like 95% sure the code is correct so I'm not sure why.

    Edit - Just tried it in Chrome and it worked fine, it isn't working in Firefox for some reason.

    Edit - Reinstalled Firefox and now it works fine.
Sign In or Register to comment.