0 votes
by (2.7k points)
edited by

I am using this auto popup macro:

/* Usage: <<autopopup "Some Pasage">> */
macros.add("autopopup", {
	version : { major : 1, minor : 0, revision : 0 },
	handler : function () {
		if (this.args.length === 0) {
			return this.error("no passage name specified");
		}

		var dialog = UISystem.setup("popup");
		new Wikifier(dialog, tale.get(this.args[0]).processText().trim());
		UISystem.open();
	}
});

But in twine 2.2.1 and sugarcube 2.21.0 it returns this error:

Apologies! An error has occurred. You may be able to continue, but some parts may not work properly.

Error [tw-user-script-0]: macros.add is not a function.

What should I change?

Edit:

Looked at the twine 2 popup macro and changed a few things. Here is the new code:

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

		var	dialog = UI.setup(title, "popup");
		new Wikifier(dialog, tale.get(passage).processText().trim());
		UISystem.open();
	}
});

And here is the new error:

Apologies! An error has occurred. You may be able to continue, but some parts may not work properly.

Error: cannot execute macro <<autopopup>>: Story.get title parameter cannot be a function.

Stack Trace:
Wikifier</t</<.value@file:///home/pi/twine_2.2.1/index.html#!/stories/faf09f4c-c592-4d02-a722-67964bf7ec3e/play:166:11134
.handler/<@file:///home/pi/twine_2.2.1/index.html#!/stories/faf09f4c-c592-4d02-a722-67964bf7ec3e/play:167:26969
MacroContext</e</<.value/</<@file:///home/pi/twine_2.2.1/index.html#!/stories/faf09f4c-c592-4d02-a722-67964bf7ec3e/play:167:12322
MacroContext</e</<.value/<@file:///home/pi/twine_2.2.1/index.html#!/stories/faf09f4c-c592-4d02-a722-67964bf7ec3e/play:167:12136
t/<@file:///home/pi/twine_2.2.1/index.html#!/stories/faf09f4c-c592-4d02-a722-67964bf7ec3e/play:164:24536
r.event.dispatch@file:///home/pi/twine_2.2.1/index.html#!/stories/faf09f4c-c592-4d02-a722-67964bf7ec3e/play:60:10263
r.event.add/q.handle@file:///home/pi/twine_2.2.1/index.html#!/stories/faf09f4c-c592-4d02-a722-67964bf7ec3e/play:60:8325

At least the story starts now though.

1 Answer

+1 vote
by (62.7k points)
selected by
 
Best answer

I'll reply to this once I get home (currently at the clinic).

Though, I'll say now the version of Twine is irrelevant here.  Your problem is attempting to use ancient code written for SugarCube v1 in v2 without doing the necessary conversion.


[EDIT]

Here's an updated version of the macro for SugarCube v2:

/* 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();
	}
});

PS: DIY instructions for converting code written for SugarCube v1 to v2—it only covers the essentials.

by (2.7k points)
Thanks, this works perfectly! It also solves one of my other questions: how to change the contents of a popup. Close it, and then make an auto popup of the new page.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...