0 votes
by (2.7k points)

I have been using the "popup" macro for SugarCube found here. Any way to make links within it change the passage in the popup (NOT the passages behind the poupup). Will this require more Javascript? And how to do it?

1 Answer

0 votes
by (2.7k points)
selected by
 
Best answer

Nevermind, i fixed it. For all who want to do it for themselves:

1. Add this code to your Story Javascript:

/* Usage: <<autopopup "Pasage Name">> */
Macro.add('autopopup', {
	handler : function () {
		if (this.args.length === 0) {
			return this.error('no passage name specified');
		}

		var passage = this.args[0];

		Dialog.setup(passage, 'popup');
		Dialog.wiki(Story.get(passage).processText().trim());
		Dialog.open();
	}
});

Then use this code in your story  (for a link):

<<link "Link Name">><<script>>UI.close()<</script>><<autopopup "Next passage to display">><</link>>

Or this (for a button):

<<button "Link Name">><<script>>UI.close()<</script>><<autopopup "Next passage to display">><</button>>

What this does (for total noobs) <<button>> and <</button>> form a button. <<link>> and <</link>> form a link. Between <<script>> and <</script>> any javascript is executed (UI.close() means close the popup). <<autopopup>> is what the Javascript above defined: a popup of a story passage.

by (68.6k points)

You shouldn't be using UI.close() as it's a SugarCube v1 API.  The correct SugarCube v2 API is Dialog.close().

Also.  There's no need to close the dialog beforehand to achieve the results you apparently want.  Simply invoking the macro again should be sufficient.  For example:

<<link "Link Text">><<autopopup "Passage Name">><</link>>
<<button "Link Text">><<autopopup "Passage Name">><</button>>

 

...