u/TigerSauce2019

Trouble with nested span replacements

As the title says, I've been using <span id="name'> and <<replace "#name">> to give the players choices without advancing the passage and also making the unselected choices disappear. However, when I try to use one of these inside another <<replace>> macro, it hangs and doesn't display any of the passage text at all. Rough example below:

&lt;span id="first"&gt;&lt;&lt;link 'Say something comforting'&gt;&gt;&lt;&lt;replace "#first"&gt;&gt;
Text text text
&lt;&lt;/replace&gt;&gt;&lt;&lt;/link&gt;&gt;
&lt;&lt;link 'Say something callous'&gt;&gt;&lt;&lt;replace "#first"&gt;&gt;
Text text text
&lt;span id="second"&gt;&lt;&lt;link 'Apologize'&gt;&gt;&lt;&lt;replace "#second"&gt;&gt;
Text text text
&lt;&lt;/replace&gt;&gt;&lt;&lt;/link&gt;&gt;
&lt;&lt;link 'Double down'&gt;&gt;&lt;&lt;replace "#second&gt;&gt;
Text text text
&lt;&lt;/replace&gt;&gt;&lt;&lt;/link&gt;&gt;
&lt;/span&gt;
&lt;/span&gt;

Is there any way to make this work, or am I just being greedy and I should advance the passage with the nested choice?

reddit.com
u/TigerSauce2019 — 4 days ago

Hey all! First time posting, looking for some help creating custom classes in SugarCube 2. I've referenced the documentation, and I think everything should be fine, but I keep getting errors. Code is pasted below:

window.Stat = class Stat {
  constructor(config) {
    this.name = '(none)';
    this.value = 1;
    this.xp = 0;
    this.isFlagged = false;
        
    Object.keys(config).forEach(prop =&gt; {
      this[prop] = clone(config[prop]);
    });
  }
    
    clone() {
      return new this.constructor(this);
  }

  toJSON() {
    var ownData = {};
    Object.keys(this).forEach(prop =&gt; {
      ownData[prop] = clone(this[prop]);
    });
    return Serial.createReviver(`new ${this.constructor.name}($ReviveData$)`, ownData);
  }
};

Specifically, I am getting the following errors:

  • When code is used as is: "Error: Serial is not defined."
  • When attempting to import serial at the top of my Story JavaScript: "Error [tw-user-script-0]: import declarations may only appear at top level of a module."
  • When trying to load a save after commenting out the Serial.createReviver line: "Can't access property "value", patched is undefined."

Any help is appreciated!

reddit.com
u/TigerSauce2019 — 9 days ago