0 votes
by (120 points)

For some reason, I keep getting an error saying my "if" macro is set up wrong, even though I think I'm following the instructions correctly.


 

(set: _lastpassage to (history:)'s last)

(if: _lastpassage is "charter inputs")[**Affecting the [[charter|charter inputs]]**
    * bullet points here
    * some have (parentheses at the end)]

gives me

The (if:) command should be assigned to a variable or attached to a hook.►
Macros like this should appear to the left of a hook: (if: _lastpassage is "Project charter inputs")[Some text]

So I tried it with this:

(set: _lastpassage to (history:)'s last)

(if: _lastpassage is "charter inputs")(show: ?charter)

|charter)**Affecting the [[charter|charter inputs]]**
    * bullet points here
    * some have (parentheses at the end)

And that gives me this:

The (if:) command should be assigned to a variable or attached to a hook.►
Macros like this should appear to the left of a hook: undefined[Some text]


|charter)Affecting the project charter <etc etc>

 

So.... How do I do this right so that a) I don't get the error message and b) the hook name doesn't show up at the beginning of my text?

1 Answer

0 votes
by (159k points)
edited by

The placement of the close square bracket of your (if:) macro's associated hook is causing issues for the story format's TwineScript parser, this issue can be simple fixed by moving it to the next line like so.

(if: _lastpassage is "charter inputs")[
	**Affecting the [[charter|charter inputs]]**
	* bullet points here
	* some have (parentheses at the end)
]

... and you can use Collapsing Whitespace markup and/or Escaped Line Break markup to remove any unwanted line break <br> elements injected into the generated HTML

The block based unorder list <ul> element you are adding to the passage will result in the same issue as this question, and you can use similar CSS in your project's Story Stylesheet area to fix it. In your specific case that CSS would be.

ul {
	display: inline-block;
	min-width: 100%;
}


You don't state if the code in your example will be used in the first Passage of your project, it it is then you will need to check the length of the Array returned by the (history:) macro because trying to access the last element of an empty Array will result in an error. In this case your code would need to be changed to something like the following

(set: _history to (history:))
(if: _history's length > 0)[
	(set: _lastpassage to _history's last)
	(if: _lastpassage is "charter inputs")[
		**Affecting the [[charter|charter inputs]]**
		* bullet points here
		* some have (parentheses at the end)
	]
]

 

by (120 points)
That fixed it, thanks!
...