0 votes
by (710 points)

Is there any way to use a dialog box to link to another dialog box? Ideally, the second box would pop up after clicking a link from within the first box. I am using Chapel's dialog macro (https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/scripts/dialog-api-macro-set.js). My code is as follows:

<<link 'Talk to Robot'>>
	<<set _option to "">>
	<<dialog 'Player'>>\
		You talk to the robot.
		<<link "What is 2 + 2?">><<set _option to "1">><</link>>
		<<link "What is 3 + 3?">><<set _option to "2">><</link>>
	<</dialog>>
	
	<<if _option is 1>>
		<<dialog 'Claire'>>\
			"Beep! 2 plus 2 is four."
		<</dialog>>
	<<elseif _option is 2>>
		<<dialog 'Player'>>\
			"Beep! 3 plus 3 is six."
		<</dialog>>
	<</if>>
<</link>>

Thanks!

1 Answer

+1 vote
by (159k points)

ChapelR's Dialog Macro internally uses SugarCube's Dialog API to show it's dialog, and as I understand things due to how that API is implemented only a single Dialog can be shown at a time.

This can be demostrated using the following example with will result in only the 2nd of the two dialogs being shown.

<<link "Open Two Dialogs?">>
	<<script>>
		Dialog.setup();
		Dialog.wiki("Contents of Dialog 1");
		Dialog.open();

		Dialog.setup("Character Sheet");
		Dialog.wiki("Contents of Dialog 2");
		Dialog.open();
	<</script>>
<</link>>


You could use the above behaviour to chain a series of dialogs, and the following shows one very basic way to do that using ChapelR's macro..

<<link 'Talk to Robot'>>
	<<set _option to "">>
	<<dialog 'Player'>>\
		You talk to the robot.
		<<link "What is 2 + 2?">>
			<<set _option to "1">>
			<<dialog 'Claire'>>\
				"Beep! 2 plus 2 is four."
			<</dialog>>
		<</link>>
		<<link "What is 3 + 3?">>
			<<set _option to "2">>
			<<dialog 'Player'>>\
				"Beep! 3 plus 3 is six."
			<</dialog>>
		<</link>>
	<</dialog>>
<</link>>

 

...