Hey there,
I'm using:
Twine 2.1
SugarCube 2.14
I'm trying to call a widget inside my JS function to print out actions that would apply to transferable game items (basically moving an item from one container to the other). This would solve a problem to which I find no work around at the moment in sugarcube and it would allow me to stream line moving items from containers to other containers and between NPC characters and the player (later on I would want to turn my containers into objects with their own names, inventory, size, etc.).
var $list = $(document.createDocumentFragment());
$list.append('<<transferContainerItemToPlayer' +' $' + container_name + '\"' + item.id + '\"' + ">>").append('<br>');
Widget code that I'm trying to call from "InventoryManagmentWidgets" passage ("widget" tag has been defined in this passage).
@
<</if>>\
<</widget>>\
Now, what I get is something like this:
<>
When I tried escaping the '<' character and '>' character respectively I ended up with the same results.
Is there any way to call widgets defined in a passage and calling it somehow with arguments?
Thank you for your help in advance!
Comments
Second. You cannot use the standard <jQuery>.append() method with non-HTML and/or non-standard-HTML markup. For SugarCube's own markup and/or its HTML extensions, you need to use SugarCube's <jQuery>.wiki() extension method.
Here's a corrected example: I moved the <br> inside the same invocation as the widget, since with the code as shown there was no point in it being separate.
Thank you again for answering in such a rapid pace.
The problem unfortunately still remains.
I still get "<>" instead of the linkreplace stuff that I specified for the user to click.
I tried to simplify the example and implement a very simple widget:
This would still yield this: "<>" instead of "this is my widget!".
I tried the following test cases:
The second one worked as intended.
So here is what I'm trying to do in the code that prints the items and the actions corresponding to each item:
Passages were printed (appeneded using append()) unclickable text:
In the previous case where I had the '<>'s appear I called my JS function this way:
<<listContainerItems $cabinet_inventory "cabinet_inventory">>
where $cabinet_inventory is an array and "cabinet_inventory" string is used to form the story variable name.
Now calling this alone worked nicely:
but if I try to call append() to add more of these entries they would get transformed into normal text.
The solution was using wiki in every entry where I needed to call a widget.
So, what we learn here today is not to use append on content that needs to be "wikified".
Thanks for your patience @TheMadExile, I really appreciate the quick and accurate help!
Thanks again TheMadExile! I'll donate next week! You are being extremely helpful and competent! I think this needs rewarding