So, from my understanding, Twine 2 has no means of passing parameters into passages.
I could be wrong, but that's what it seems like.
I'm using sugarCube, and the second parameter of display is an html tag, not a custom parameter(s) for the passage
I have some template passages that I want to call, and then change very slightly passed on parameters.
I could set varaibles before I call <<display>>, but that's polluting the global variable environment.
I figured I could use a custom macro to solve this, but I think I've hit a dead end.
This is what I've got thus far.
<<script>>
Macro.add("RenderPassage", {
version: { major: 0, minor: 1, patch: 0 },
handler: function () {
var source_text = this.args[0];
var params = this.args[1];
var passage = "<<display " + source_text + ">>";
new Wikifier(this.output, passage);
}
});
<</script>>
<<RenderPassage 'mactest', array('test')>>
I have a params var, but I would have no idea how to pass that into the passage I'm calling with Wikifier.
Does anyone have a solution to this problem? Or perhaps I'm going about what I'm trying to do in entirely the wrong way.
Comments
I'm going to assume that you're using SugarCube v1.x.
You probably just want to use a <<widget>> macro, which is the equivalent of what you're trying to do with <<display>>.
It's kind of a shame that the widget doesn't have its own scope, so any variables written there will pollute the global environment, but... whatevs!
This should work well enough.
Thanks!
If you're referring to auto-globals, simply don't use them. Use a story variable and <<unset>> it when you're finished with it. About the only time I suggest using auto-globals is when defining utility functions or objects—even then, you don't have to use them as SugarCube provides the setup object for that purpose.