A sugarcube widget just saved me 12 Kb

- Posted in Coding by

I'm proud of a programming accomplishment I've made: I've been developing an introductory tutorial series covering Twine 2.10.0 and Sugarcube 2.37.3 — for an interested coworker.

I've been naming the tutorial passages after this convention:

TwineLesson001Passage001
TwineLesson001Passage002
etc.

Well, I had been using a block of Twinescript like the following in order to implement some cute back/forward navigation icons (shown below):

But I got to thinking to myself, "Self, there has to be a way to use a widget or function so that I'm not pasting the equivalent of a small paragraph in every single tutorial passage, just to implement this."

It took me awhile to incrementally write code, test, repeat to get the above. Just three lessons into a tutorial series (weighing in at 51 passages), my Twee3 file was 39 Kb. Using the above widget allowed me to trim that down to 27 Kb.

Build.yml not working

- Posted in Coding by

name: Build #found this build file on the web somewhere on: push: branches: - main

# Always force the use of Go modules
env:
  GO111MODULE: on

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Setup go
        uses: actions/setup-go@v5
        with:
          go-version: '1.22'
          cache: false

      - name: build game
        run: |
          go get github.com/tmedwards/tweego
          export PATH=$PATH:$(go env GOPATH)/bin
          mkdir -p ${{vars.OUTPUT_DIRECTORY}} && touch ${{vars.OUTPUT_DIRECTORY}}/${{vars.OUTPUT_FILENAME}}
          tweego ./src -o ${{vars.OUTPUT_DIRECTORY}}/${{vars.OUTPUT_FILENAME}}

      - name: Deploy to Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.PERSONAL_TOKEN }}
          publish_branch: pages
          publish_dir: ./${{vars.OUTPUT_DIRECTORY}}/

Linking to passages by URL

- Posted in Coding by

Put the following code into the Javascript section of your Twine project:

/* Anchor Link to Passage - Start */
if ("onhashchange" in window) {  // event supported
    window.onhashchange = function () {
            hashChanged();
    };
} else {  // event not supported
    window.setInterval(function () {
            if (window.location.hash != setup.storedHash) {
                    hashChanged();
            }
    }, 100);
}
function hashChanged() {
    if (Engine.isIdle()) {
            if (window.location.hash && (setup.storedHash != window.location.hash)) {
                    setup.storedHash = window.location.hash;
                    var anchor = decodeURI(window.location.hash.substring(1));
                    if (Story.has(anchor) && (passage() !== anchor)) {
                            Engine.play(anchor);
                    }
            } else {
                    // Comment out the following line of code if you don't want the
                    // anchor link of the current passage displayed in the URL bar.
                    window.location.hash = encodeURI(passage());
            }
            // Comment out the following line of code if you don't want the
            // title of the page set to the passage name.
            document.title = passage();
    } else {
            setTimeout(hashChanged, 100);
    }
}
$(document).on(':passageend', function () { hashChanged(); });
/* Anchor Link to Passage - End */

Next, put the following into a header passage, but feel free to restrict its use with passage tags.

Blessed are the Peacemakers

- Posted in SundaySchool by

Blessed are the Peacemakers

Why do you think peacemaking receives so little attention today? (Perhaps it is considered ineffective. Perhaps because it can take such a lengthy investment of time and good will. Perhaps because its goal is not just the cessation of violence but the redemption of all parties.

Iterate over passages to filter them

- Posted in Coding by
setup.getPassageNames = function() {
            const excludedNames = ['StoryInit', 'Main']; 
            const excludedTags = ['widget', 'nonono']; 
            const passageNames = [];
            
            $('tw-passagedata').each(function() {
                const name = $(this).attr('name');
                const tags = $(this).attr('tags');
                let safeTags = true;
                
                    if (excludedNames.indexOf(name) === -1) {
                      
                      for (let i = 0; i < excludedTags.length; i++) {
                        if (tags.includes(excludedTags[i])) {
                            safeTags = false;
                            break;
                        }
                      }
                      
                      if (safeTags) {
                        passageNames.push(name);
                      }  
                }
            });
        
            return passageNames; 
        };
        
        
    <<set _possiblePlaces = setup.getPassageNames()>>
    <<set _randomPassage = _possiblePlaces.random()>>

Beatitude 5 - Blessed are the Merciful

- Posted in SundaySchool by

Blessed are the Merciful

Matthew 5: 7 —Blessed are the merciful, for they will be shown mercy.

The Greek word makarios (Μακάριος) means "blessed," "happy," "fortunate," or "privileged". It appears in the New Testament 50 times. Meaning Makarios is the closest Greek word to the English word "happy". It can describe someone who has a special advantage or desirable position. For example, the ancient Greeks used makarios to describe their gods, who were blessed with divine power.

Primary Twine story formats and essential tooling

- Posted in Coding by

Primary Twine story formats can be downloaded with this link, or with this one. Here is another download link.

And of course I must link to the three most important resources (ChapelR's Tweego, Chris Klimas' Twine, and Visual Studio Code. These are bundled together and can be downloaded here and here and here.

Hiev's browser storage tool is a must-have. The same author produced a nice collection of sample code, which I make downloadable here.

Here is Gwentastic's Twee File Splitter, and here is another download link. I've also backed it up to my OpenDrive and it's located here on my Onedrive account.

Finally, my go-to SugarCube template for getting new projects initiated.

Tweego compiler installer for Windows

- Posted in Coding by

Here is the download link for the Tweego compiler for Windows. It can also be downloaded here and here. Here is my template to hit the ground running with Twee3/Tweego dev. However, I recommend that, instead, you install Tweego for Windows using ChapelR's installer, and then download the much slimmer template I made here.

Remove side bar in Sugarcube 2

- Posted in Coding by

Add the following to the javascript portion of your twee file:

$('#ui-bar').remove(); 
$(document.head).find('#style-ui-bar').remove();
Page 2 of 3