Howdy, Stranger!

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

Reading through Sugarcube 2's macro documentation

I came across this . Can someone explain the what and why here? What does "..." do and
http://www.motoslave.net/sugarcube/2/docs/macros.html
Passing an expression as an argument.

...

For example, the following will not work because the macro parser will think that you're passing five discrete arguments, rather than a single expression:
<<click "Wake " + $friend + ".">> … <</click>>
You could solve the problem by using a temporary variable to hold the result of the expression, then pass that to the macro. For example:
<<set _text to "Wake " + $friend + ".">>\
<<click _text>> … <</click>>
A better solution, however, would be to use a backtick[1] expression (`…`), which is really just a special form of quoting available in macro arguments that causes the contents of the backticks to be evaluated and then yields the result as a singular argument. For example:
<<click `"Wake " + $friend + "."`>> … <</click>>
I tried running the code myself. It looks like in the first code example it thinks '+' is the name of a passage.
Error: the passage "+" does not exist. What does the "..." do exactly as a backtip expression? How does the ` after the "." in the 3rd code example make it different and what use does the _text (a temporary variable) provide?

Comments

  • In those particular cases the three full stops ... are being used as a placeholder for whatever code is contained within the body of the <<click>> macro. It is the same as when a person replying to a comment removes some of the original comment to shorten it.
    eg.
    I tried running the code myself. It looks like ... the name of a passage.

    A. SugarCube uses space character(s) (or white space) to separate the parameters being sent to it's macros, it tries to determine the data type of each of those parameters, and by default it does not evaluate complex expressions in the parameter area of a macro.

    Because of this it breaks the "Wake " + $friend + "." complex expression in the first example down something like the following:

    note: the order I have the following steps may not be correct.

    1. replace the $friend variable with its value.
    2. convert the + operators to String values.
    3. pass five parameters to the <<click>> macro.

    B. In SugaCube any variable name that starts with an underscore is treated as a temporary variable, it is local to that passage only and it's value will not be remembered/stored once the Reader leaves the current passage.

    C. In SugarCube 2.7.0 and above you can no use the backtick to force an complex expression to be evaluated before it is passed/processed as a parameter of a macro. This feature helps get around the issue in point A.
  • I suppose I'll reply as well.
    What does "..." do
    In context, it shows that some content has been elided—usually content that is not germane to the topic at hand. It's a fairly standard practice.

    As greyelf surmised, it denotes the omission of some code which would normally go there. In all of the instances in which it is used there—in the interiors of the <<click>> macros and when showing the backtick quotes—it denotes that code, which was not relevant to the example at hand, was omitted for brevity.

    How does the ` after the "." in the 3rd code example make it different
    That's the closing backtick quote of the backtick expression. You'll note that there's an opening backtick as well. The content between the backticks is evaluated as an expression and returned to the macro as a single argument.

    what use does the _text (a temporary variable) provide?
    While it's not the greatest bit of documentation yet, the TwineScript document explains the difference between the two types of variables and their basic uses.
Sign In or Register to comment.