0 votes
by (870 points)

I understand you can use jQuery's wiki() function to execute TwineScript, including macros. I wish to make a method function for an object that passes the object as an argument to a SugarCube macro. Is there a way to get the Twine variable name of an object within a method function?

I'd like something like this:

$.wiki('<<macro '+(this object's variable name in Twine)+'>>')

 

1 Answer

0 votes
by (44k points)
selected by
 
Best answer

You'd have to convert the object into a Twine story variable or temporary variable, using State.variables or State.temporary, respectively.  For example:

State.temporary.someObject = someObject;
$.wiki('<<macro _someObject>>');

Hope that helps!

by (870 points)
Okay, that executes! Unfortunately, I seem to have encountered another issue: wiki() won't execute <<print>> macros. Is there any way to do this?
by (44k points)

Yeah, "$.wiki('whatever');" sends the output nowhere.

If you want the output to appear somewhere as the passage is initially rendered, then you'd want to do something like this:

<span id="test"></span>
<<script>>
$(document).one(":passagerender", function (ev) {
	State.temporary.someObject = someObject;
	$(ev.content).find("#test").wiki('<<macro _someObject>>');
});
<</script>>

However, if you're trying to display it after the passage as already rendered (for example, when the user clicks a button), then you could do something like this:

<span id="test"></span>
<<button "Click me">><<script>>
	State.temporary.someObject = someObject;
	$("#test").wiki('<<macro _someObject>>');
<</script>><</button>>

Have fun!  :-)

by (870 points)
Ah, yeah, that's not worth it. DX I just made it a widget instead. Thanks anyway!
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...