u/TigerSauce2019

TEMPORARILY Disable Back Button

[SOLVED] Hey folks. I'm building a game where some actions have a chance of negative consequences. I want to prevent the player from abusing the Back mechanic to avoid those consequences, but I want to keep it in the game for general navigation purposes.

I've searched online, and I've only found references to things that either disable it for the whole game (adding Config.history.controls = false; to the Story JavaScript) or that disable the entire sidebar (tagging the passage "risky" and adding body.risky #ui-bar {display: none;} to the Stylesheet), which I don't want to do.

Help is appreciated :) Story Format is SugarCube 2.37.3

reddit.com
u/TigerSauce2019 — 7 days ago

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 — 13 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 — 17 days ago