I'm using a libray, where is the function?

jmnevil54
12 Oct 2017, 18:35

So I'm using a library for the first time... then I opened up the library for editing. It's this one. http://textadventures.co.uk/forum/samples/topic/3789/adding-a-second-inventory-object-pane

So, I tried opening it. I looked at the code to see they have some sort of function/functions, but I can't find those functions. I figure they are in the InvLib file, but I can't view that because it's not an .aslx file.

Also, I'm trying to copy-paste things into my online game.


K.V.
12 Oct 2017, 18:38

Hello, jmne!

Pixie has one on his GitHub wiki. It's the one I use, and works great.

https://github.com/ThePix/quest/raw/master/InvPane2.aslx

https://github.com/ThePix/quest/wiki/Second-Inventory-Library


jmnevil54
12 Oct 2017, 18:55

*shakes head
Too complicated.

(I also tried copy-pasting The Pixie's code in the offline editor, in a blank game, but I kept getting errors, so I quit.)


K.V.
12 Oct 2017, 19:03

Ah... I see.

I'll check out Jay's.

Did you get the first one in the thread?

Jay posted one (see this link), then Pixie posted one (see this link).


jmnevil54
12 Oct 2017, 19:20

The first one.
... *messes around with the second one...

...No, still can't find it.....


K.V.
12 Oct 2017, 19:32

SetInventory2 should be the function you're looking for.

You will also need SetInventory2Label.

InvPane2.aslx
<library>
  <function name="SetInventory2Label" parameters="label">
    JS.eval("$('#Inventory2Label a').html('" + label + "');")
  </function>
  <function name="SetInventory2" parameters="objects">
    <![CDATA[
    // Build the JSON string for these.
    s = ""
    count = 1
    foreach (o, objects) {
      verbs = ""
      foreach(verb, o.inventoryverbs) {
        if (verbs <> "") {
          verbs = verbs + ","
        }
        verbs = verbs + "\"" + verb + "\""
      }
      if (s <> "") {
        s = s + ", "
      }
      s = s + "\"k" + count + "\": {\"Text\":\"" + GetDisplayAlias(o) + "\",\"Verbs\":[" + verbs + "],\"ElementId\":\"" + o.name + "\",\"ElementName\":\"" + GetDisplayAlias(o) + "\"}"
      count = count + 1
    }
    s = "{" + s + "}"
    //msg(s)
    JS.updateInventory2("Inventory2", s)
    ]]></function>
</library>


AdditionalPane.aslx (the game)
<!--Saved by Quest 5.4.4873.16527-->
<asl version="540">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <include ref="InvPane2.aslx" />
  <game name="AdditionalPane">
    <gameid>04272098-2de5-4068-af3c-92bb738310e4</gameid>
    <version>1.0</version>
    <firstpublished>2013</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <enter type="script">
      SetInventory2Label("Bag")
      ol = NewObjectList()
      list add(ol, AnObject3)
      list add(ol, AnObject4)
      SetInventory2(ol)
    </enter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="AnObject">
      <inherit name="editor_object" />
      <inherit name="container_open" />
      <alias>Object 1</alias>
      <use type="boolean">false</use>
      <take />
    </object>
    <object name="AnObject2">
      <inherit name="editor_object" />
      <inherit name="container_open" />
      <alias>Object 2</alias>
      <use type="boolean">false</use>
      <take />
    </object>
  </object>
  <object name="room2">
    <inherit name="editor_room" />
    <object name="AnObject3">
      <inherit name="editor_object" />
      <alias>Object 3</alias>
    </object>
    <object name="AnObject4">
      <inherit name="editor_object" />
      <alias>Object 4</alias>
    </object>
  </object>
  <javascript src="InvPane2.js" />
</asl>

InvPane2.js (the JavaScript file)
var Inventory2Verbs;
$(function() {
  var s = "<div id='Inventory2Holder' style='padding-left:0px'> \
            <h3 id='Inventory2Label'><a href='#'>Inventory 2</a></h3> \
            <div id='Inventory2Accordion'> \
                <div id='Inventory2Wrapper' class='elementListWrapper'> \
                    <ol id='lstInventory2' class='elementList ui-selectable'> \
                    </ol> \
                </div> \
                <div class='verbButtons'> \
                    <button id='cmdInventory21' type='button' onclick='paneButtonClick(\"#lstInventory2\",$(this));' style='display:none' role='button' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'><span class='ui-button-text'></span></button> \
                    <button id='cmdInventory22' type='button' onclick='paneButtonClick(\"#lstInventory2\",$(this));' style='display:none' role='button' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'><span class='ui-button-text'></span></button> \
                    <button id='cmdInventory23' type='button' onclick='paneButtonClick(\"#lstInventory2\",$(this));' style='display:none' role='button' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'><span class='ui-button-text'></span></button> \
                    <button id='cmdInventory24' type='button' onclick='paneButtonClick(\"#lstInventory2\",$(this));' style='display:none' role='button' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'><span class='ui-button-text'></span></button> \
                    <button id='cmdInventory25' type='button' onclick='paneButtonClick(\"#lstInventory2\",$(this));' style='display:none' role='button' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'><span class='ui-button-text'></span></button> \
                    <button id='cmdInventory26' type='button' onclick='paneButtonClick(\"#lstInventory2\",$(this));' style='display:none' role='button' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'><span class='ui-button-text'></span></button> \
                    <button id='cmdInventory27' type='button' onclick='paneButtonClick(\"#lstInventory2\",$(this));' style='display:none' role='button' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'><span class='ui-button-text'></span></button> \
                    <button id='cmdInventory28' type='button' onclick='paneButtonClick(\"#lstInventory2\",$(this));' style='display:none' role='button' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'><span class='ui-button-text'></span></button> \
                    <button id='cmdInventory29' type='button' onclick='paneButtonClick(\"#lstInventory2\",$(this));' style='display:none' role='button' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'><span class='ui-button-text'></span></button> \
                </div> \
            </div> \
            </div>";
    $(s).insertBefore("#statusVarsLabel");
    $("#Inventory2Holder").multiOpenAccordion({ active: [0] });
    $("#lstInventory2").selectable({
        selected: function (event, ui) {
            $(ui.selected).siblings().removeClass("ui-selected");
            updateVerbButtons($(ui.selected), Inventory2Verbs, "cmdInventory2");
        }
    });

});

function updateInventory2(listName,listData) {
	listData = JSON.parse(listData);
    var listElement = "#lst" + listName;
    var buttonPrefix = "cmd" + listName;
	var idPrefix = buttonPrefix;
	eval(listName + "Verbs = new Array();");

	var verbsArray = eval(listName + "Verbs");

    var previousSelectionText = "";
    var previousSelectionKey = "";
    var foundPreviousSelection = false;

    var $selected = $(listElement + " .ui-selected");
    if ($selected.length > 0) {
        previousSelectionText = $selected.first().text();
        previousSelectionKey = $selected.first().data("key");
    }

    $(listElement).empty();
    var count = 0;
    $.each(listData, function (key, value) {
        var data = value;
        var objectDisplayName = data["Text"];

        verbsArray.push(data);

        if (true) {
            var $newItem = $("<li/>").data("key", key).data("elementid", data["ElementId"]).data("elementname", data["ElementName"]).data("index", count).html(objectDisplayName);
            if (objectDisplayName == previousSelectionText && key == previousSelectionKey) {
                $newItem.addClass("ui-selected");
                foundPreviousSelection = true;
                updateVerbButtons($newItem, verbsArray, idPrefix);
            }
            $(listElement).append($newItem);
            count++;
        }
    });

    var selectSize = count;
    if (selectSize < 3) selectSize = 3;
    if (selectSize > 12) selectSize = 12;
    $(listElement).attr("size", selectSize);
    
    if (!foundPreviousSelection) {
        for (var i = 1; i <= verbButtonCount; i++) {
            var target = $("#" + buttonPrefix + i);
            target.hide();
        }
    }
}


jmnevil54
12 Oct 2017, 19:38

Yeah... Well, that's impossible... At least I tried...


The Pixie
12 Oct 2017, 20:28

You cannot open library files up in Quest, but you can in a text editor. I use Notepad++.

Are you doing this with the intention of copying functions into an on-line game? Generally that will be fine, just remember to set the parameters and type as well as pasting in the code.

However... Jay's second inventory thing uses a JavaScript file as well, and you cannot do that in the on-line version. My library, which is based on Jay's, embeds the JavaScript in an attribute, and again you cannot do that on-line.


K.V.
13 Oct 2017, 01:32

jmne,

Does the game included in Jay's ZIP file work correctly for you?

If no:

Did you unzip the ZIP file before you tried?

If I try to run the game from within the zipped file, I get this:

image


The example game works for me, as long as I extract the files first.


jmnevil54
13 Oct 2017, 15:07

It works, it works...


K.V.
13 Oct 2017, 17:09

Hurray!


hegemonkhan
13 Oct 2017, 17:24

all quest files (game files and library files) have to be 'XXX.aslx' files, so if you download a file that is a zip file, you got to unzip it, to get at its 'XXX.aslx' quest files. You can also just try changing the extension too, if the downloaded file is a text (XXX.txt) file.

the 'XXX.quest' file is only for the quest servers online, which is created via 'publishing' it to them.


The Pixie
13 Oct 2017, 18:42

Actually library files can be .xml. This can be useful because you can have them open in Notepad++ by default while .aslx open in Quest by default. Also, if you screw up the XML in a .xml file, you can open it in a browser, and it may give an idea of where it is wrong.

Apart from that, yes.


jmnevil54
13 Oct 2017, 19:47

The Pixie

You cannot open library files up in Quest, but you can in a text editor. I use Notepad++.

Are you doing this with the intention of copying functions into an on-line game? Generally that will be fine, just remember to set the parameters and type as well as pasting in the code.

However... Jay's second inventory thing uses a JavaScript file as well, and you cannot do that in the on-line version. My library, which is based on Jay's, embeds the JavaScript in an attribute, and again you cannot do that on-line.

So this all doesn't matter.

Thanks for trying, anyways.


hegemonkhan
14 Oct 2017, 02:43

you can copy the library file into your game file... as that's all a library file actually does, when it gets compiled, lol. But library files are nice for our organization, sanity (or insanity... working with a lot of library files can be frustrating too, for me anyways, lol), editing, trouble-shooting, and also encapsulation design.