Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Display a passage with paramters

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

  • Twine 2 has nothing to do with how story formats function. It's just the IDE/compiler.

    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>>.
  • That definitely gave me what I needed.

    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!
  • edited December 2015
    I assume you're talking about story variables (e.g. $foo). If widgets couldn't access them, then they wouldn't be very useful. Within widgets, or elsewhere, you may always use the <<unset>> macro to purge story variables which are no longer necessary.

    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.
  • Works well enough for me, thanks Exile.
Sign In or Register to comment.