Popup Question

I'm trying to make Quest's built-in popup box appear manually via a script. So I want to call the built-in function ProcessTextCommand_Popup. This function uses two parameters, section and data. I think what goes into section is the text processor popup directive, i.e., {popup:somelink:someimageandtext}. My question is -- what goes into data?

Here is Quest's built-in popup function. section is only listed at the beginning, and data is only listed at the very end:

section = Mid(section, 7)
ary = Split(section, ":")
s1 = StringListItem(ary, 0)
list remove (ary, s1)
s2 = Join (ary, ":")
id = JSSafe(s1) + GetRandomInt(0, 999999999)
link = game.defaultlinkforeground
if (HasString(game, "altlinkforeground")) {
  link = game.altlinkforeground
}
s = "<span  style=\"cursor:pointer;color:" + link + ";\" onclick=\"$('#" + id + "').css('display', 'block');\">" + s1 + "</span><div id=\"" + id + "\" class=\"w3-theme-border\" style=\"position:fixed;z-index:9999;display:none;cursor:pointer;left:50px;top:40%;width:40%;background-color:" + game.defaultbackground + ";border:2px solid " + game.defaultforeground + ";color:" + link + ";border-radius:5px;padding:5px;\" onclick=\"$('#" + id + "').css('display', 'none');\"><p>"
s = s + s2 + "</p></div>"
return (ProcessTextSection(s, data))

I think data is a dictionary that holds information some text processor directive use, for example (and I am getting less certain at this point), the once directive uses it to track what has already been printed and so whether this is new text or not.

It has to be passed around in case one of those is inside the text that ProcessTextSection is handling.


data is a dictionary. If you're creating new text processor directives to do something like draw a table, you could use it to pass data between directives in the same string.

The only value that is put in the dictionary by default has the key fulltext, and the value is the full string that was passed to the text processor. This is used by the {once: directive to recognise whether this string has been parsed before.

If you're not using {once: in your string, you can just pass NewDictionary() as the data parameter and it won't make any difference.

However, I would suggest that calling ProcessTextCommand_Popup manually is probably overkill.
You could easily do:

  • ProcessTextCommand_Popup ("somelink:someimageandtext", NewDictionary())
    

or you could do:

  • ProcessText ("{popup:somelink:someimageandtext}")
    

The first is slightly more efficient code; the second is easier to read. And if you're more concerned with execution time, then you'd be better making your own function so you can skip the code that splits your string up into the two parameters.


@mrangel -

Hmm.....I tried your two methods with an object's look at command and they didn't work:

ProcessTextCommand_Popup ("somelink:someimageandtext", NewDictionary())

ProcessText ("{popup:somelink:someimageandtext}")

Quest would print out "look at sword", for example, but the popup wouldn't display.

I tried it this way too, with the same result:

ProcessTextCommand_Popup ("{popup:somelink:someimageandtext}", NewDictionary())

Hmm.....


What do you mean by "wouldn't display"?

Does the link appear? Does clicking on it do nothing, or generate an error in the javascript console?

Are you changing the string returned by ProcessText at all before sending it to the frontend? You might be doing something that breaks the script?

(and if you're not changing it, then it's easier to use msg ("{popup:somelink:someimageandtext}"); because msg calls ProcessText automatically)


Are you printing it with msg?

Also, it seems that you still have to lead off with "popup:".


This works for me (EDITED TO USE VARIABLE):

x = ProcessTextCommand_Popup ("popup:somelink:someimageandtext", NewDictionary())
msg(x)

What I'm trying to do is call the ProcessTextCommand_Popup function directly from an object's look command (under the object's description). So when "look at sword" is typed, or clicked on in the object's object link, or clicked on in the object's display/inventory verbs links, the popup itself will display immediately (instead of some text and the link displaying, and then you have to click on the link to display the popup).


The ProcessTextCommand_Popup command generates the HTML code to display a link which spawns a popup; exactly the same as putting a {popup: directive in the object's description.

You probably want to create your own function to do this. I'd suggest that a JS function would be more efficient for working with popups.

Off the top of my head, the code in your UI initialisation script to set this up would look like:

link = game.defaultlinkforeground
if (HasString(game, "altlinkforeground")) {
  link = game.altlinkforeground
}
JS.eval("$(function () {ShowPopup = function (id, contents) {var popup;if (! $('#'+id).length) {$('<div>', {id: id, style: 'position:fixed;z-index:9999;cursor:pointer;left:50px;top:40%;width:40%;background-color:" + game.defaultbackground + ";border:2px solid " + game.defaultforeground + ";color:" + link + ";border-radius:5px;padding:5px'}).appendTo('#divOutput').bind('click', function (e) {popup.hide();});}popup = $('#'+id);popup.html(contents).show();};});")

Then when you want to show a popup, you should be able to display it with:

JS.ShowPopup ("somename", "someimageandtext")

(I'm using the colour/style information from ProcessTextCommand_Popup because I assume that's what you want it to look like. If you want the player to be able to drag the popup around, resize it, or do more than just close it, you'd probably be better off using dialog)


Ok, I didn't realize that ProcessTextCommand_Popup only displays the link, rather than the popup. I'll play around with your code later. Thanks people!


Is there another function that would display the popup, like ProcessTextSection?


@mrangel -

I tried your code, and the popup box opens up, but is blank (devoid of any text or images).

I noticed that your 2nd parameter in ShowPopup is "contents", but the last part of your JS function ends with the variable "content":

ShowPopup = function (id, contents)

popup.html(content).show();

So I changed "content" to "contents", so that they are consistent (both say "contents"). Surprisingly, that made no difference.


Sorry about that; two silly mistakes because I was typing on my phone and not giving it my full attention. I've updated the post above.

You spotted the contentserror; I also mishandled the # before the element ID in a selector (resulting in an invalid id)

(Note that while ProcessTextCommand_Popup uses the game's colour settings each time it is called, my code puts the current values into the javascript function when it is first called; so if you change game.defaultbackground or similar during the game, the popups from this code will keep using the old value until you reload a saved game)


It seems to work now, thank you.


Log in to post a reply.

Support

Forums