Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

330
Views
How to make the JavaScript in Twine 2 work the way that I want it to?

Well, you see here I am trying to make this:

Config.saves.slots = 16;

Config.saves.onSave = function (save, details) {
    switch (details.type) {
        case 'slot':
            // code to post-process the save object from slot saves
            break;
        case 'disk':
            // code to post-process the save object from disk saves
            break;
        case 'serialize':
            // code to post-process the save object from serialize saves
            break;
        case 'autosave':
            // code to post-process the save object from autosaves
            break;
    }
};

var parts = document.getElementById("parts");
var part = parts.getElementsByClassName("part");

var chapter = document.getElementsByClassName("chapter");
var nOCPP = 966;
var nOC = 46368;

const starterChapters = new Array();
for (var seli=0; seli < chapter.length; seli++) {
    function tftgdedd(num) {
        starterChapters[num] = chapter[num].innerHTML;
    }
    tftgdedd(seli);
}

for (var seli=0; seli < part.length; seli++) {
    function tftgdedd(num) {
        part[num].addEventListener("click", function() {
            for (var sli=0; sli < chapter.length; sli++) {
                chapter[sli].innerHTML = parseFloat(starterChapters[sli]) + (nOCPP*num);
            }
        });
    }
    tftgdedd(seli);
}

for (var seli=0; seli < chapter.length; seli++) {
    function tftgdedd(num) {
        chapter[num].addEventListener("click", function() {
            // Stuff to make it so that you can travel to the content of the selected chapter, there is 46368 chapters, there is 966 chapter select buttons
        });
    }
    tftgdedd(seli);
}

Work the way that it does in normal JavaScript. It really will suck if I can't find a way to make this work, after all, if it can't work the way that I want then I will have to completely scrape the story, as I have over 58.68 billion words typed out that make up the entire story, it is too much to give up on, and if I can't get Twine 2 to work the way that I need it to then I am going to need to make the entire thing over without using a game engine, it is probably easier to find a way to make Twine 2 to work than taking the next year reprogramming the story.

I should say that I am using SugarCube v2.34.1

The Problem:

Well, when I click the test button this alert message pops up:

twinery.org says

Apologies! An error has occurred. You may be able to continue, but some parts may not work properly.

Error [tw-user-script-0]: Cannot read properties of null (reading 'getElementsByClassName').

I would like to make it so that getElementsByClassName works the way it should, also I want all normal JavaScript to be able to be used in twine 2.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!