Calling a quest function with jQuery Dialog button

Hi, recently I've been messing with this script made by K.V.

	$('#msgboxCaption').html(text);

	var msgboxOptions = {
		autoOpen: false,
		title: title,
		buttons: [
			{
				text: 'OK',
				click: function () { $(this).dialog('close'); }
			},
		],
		closeOnEscape: false,
	};

	$('#msgbox').dialog(msgboxOptions);
	$('#msgbox').dialog('open');
};

From this topic: http://textadventures.co.uk/forum/quest/topic/9-3xus0nt0yfsuyykyhlfg/external-popup-picture-over-the-gamewindow

And what I've been trying to do is add a button on the dialog that calls a quest function, is it possible?


And what I've been trying to do is add a button on the dialog that calls a quest function, is it possible?

Yes; but you can only pass exactly one parameter to the function, and I think the parameter will be automatically converted to a string.

The function you want is ASLEvent (function_name, parameter). For example, when you use the ShowMenu function in Quest, it outputs a bunch of links with onclick="ASLEvent('ShowMenuResponse', 'optionA')" or similar.


Ok, after a few tries I got it. Thanks a lot for the help!

This is how the code looks now:

$('#msgboxCaption').html(text);

        var varName = "test"
	var msgboxOptions = {
		autoOpen: false,
		title: title,
		buttons: [
			{
			     text: 'OK',
			     click: function () { $(this).click(ASLEvent('functionName', varName)); }
			},
		],
		closeOnEscape: false,
	};

	$('#msgbox').dialog(msgboxOptions);
	$('#msgbox').dialog('open');
};

It's kinda weird how the ASLEvent necessarily need to pass a parameter otherwise it won't work


That looks a bit. Wouldn't that require the player to click the button twice to make it work? It looks like when they click the OK button, all it does is change its behaviour to call a Quest function the next time it's clicked.


Nop, for some reason if I just put the ASLevent after the click: it calls the function when the dialog opens and not when the button is pressed, this way it works just fine, but I've no clue why

If u want to test it:

<!--Saved by Quest 5.8.6836.13983-->
<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Dialog test">
    <gameid>ca2e876f-fde7-43f3-9cf8-ec3711f47151</gameid>
    <version>1.0</version>
    <firstpublished>2020</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <isroom />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="Open dialog">
      <inherit name="editor_object" />
      <displayverbs type="stringlist">
        <value>Use</value>
      </displayverbs>
      <feature_usegive />
      <use type="script">
        JS.showPopup ("Dialog menu", "Click on the button!")
      </use>
    </object>
  </object>
  <function name="functionName" parameters="parameter">
    msg ("Hello world!")
  </function>
  <javascript src="javascript.js" />
</asl>

Ah… I wasn't reading it right.
Your code is binding an invalid event; but the error messages are being discarded somewhere down the line so you don't see them.

The options should be:

			     click: function () { ASLEvent('functionName', varName); }

"When the button is clicked, run a Quest function"


I think you might have tried:

			     click: ASLEvent('functionName', varName)

"Run a Quest function that returns some javascript code, then when the button is clicked run that code"


Your version now:

			     click: function () { $(this).click(ASLEvent('functionName', varName)); }

"When the button is clicked, run a Quest function that returns some javascript code, and set that code to run any time the player clicks within the dialog box in future"

(Note: two of those examples are trying to get a return value back from ASLEvent and treat it as Javascript code. This doesn't work because Quest discards the return value of a function called using ASLEvent. So it just causes an error that is ignored by the system)


Make sense, I have no knowledge of javascript so I just copied this format:click: function () { $(this).dialog('close');}

Again, thanks a lot for the help!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums