Optionally visible text?

Tweego v2.1.1
SugarCube v2.37.0-alpha.18+10004

What’s the briefest way to declare optionally visible text in-line with the rest of the passage while a story is being written?

I’ve found quite a few discussions of very similar topics, but none seem to be exactly what I’m trying to do.

Some background:

I’m writing a story in which I’d like the reader to be able to select how many viewpoints are visible, depending on whether the global variable $POV has been set to be Single, Multiple or Omnicient. I’m using Sugarcube’s Setting API to set the variable. That part seems to be working fine.

I do not want to put the optionally visible text in a separate passage.

Of course, I can control the visibility in a long-winded way by using something like

<<if $m>>
<div class="...">
optionally visible text

However, I’d like to drastically reduce the amount of typing that I have to do, with both the variable name and the <div class... being provided by the macro instead of typing them myself.

For example, I’d like to write passages containing something like

Some text which is visible at all times.

Some optionally visible text (using div and class to select a different font, etc) which can be seen when multiple POVs have been requested. That is, when $POV is "Multiple".

More text which is visible at all times.

Unfortunately, my knowledge of JavaScript is, shall we say, less than minimal.
My first thoght was to define a macro named <<ifm>> which declares an initial <div class="..."> and another macro named <</ifm>> provide the </div> (as well as whatever other closures might be appropriate.)

I’m sure Sugarcube JS developers are laughing at thie :slight_smile:

“Of course” I immediately encountered two problems with this plan:

  1. the first macro generated an error complaining that there was no </div>
  2. a slash (/) doesn’t seem to be allowed in the name of a macro (<</ifm>> )

What’s the best way to do this?

Thanks for whatever help you can provide.

SugarCube includes two ways of creating custom “macro” like functionality:

  1. The JavaScript based Macro API, with the relevant definitions being placed in the project’s Story > JavaScript area.
  2. The <<widget>> macro, with the relevant definitions being placed in a Passage that has been assigned the special widget Passage Tag.

As you don’t know JavaScript I would suggest using a Widget, specifically a “container” based one.

The following shows how to define a widget named ifm that can be used exactly like your <<ifm>> based example…

<<widget "ifm" container>>
	<<if $m>><div class="...">_contents</div><</if>>

a slash (/) doesn’t seem to be allowed in the name of a macro

When you define a Macro or a Widget you use arguments to indicate if it is container based, which lets the system know that an end-tag like <</macroname>> will be required, and one is automatically created.

1 Like


That did exactly what I wanted.

1 Like