Coding

All things computer programming related...

Dev notes for Twine story entitled Dorn

- Posted in Coding by
dev.tw
        passworded access to Developer Notes
dorn_head_foot.tw
        contains header and footer passage 
          for use with hbar and bbar tags\
dorn_intro.tw
        contains passages comprising the Intro to the game/story
dorn_2.tw
        contains ?# passages that form the beginning of this hyperfic
dorn_last.tw
        contains scripts and special passages
        contains code for the playtime macro
        contains code for the fade-in macro
        contains code for hashing to enable passwording
        contains code to implement [nosave] tag for passages
        contains Config data:
          maxSlotSaves = 3
          maxStates = 50
          saves.isAllowed conditions
        contains code to check for [noreturn] tag, for menuing
        contains code to add visits to passage(s) programmatically 
               during initialization (for testing)
        contains code in PassageReady to track total number of passage visits

Implementing passworded content in a Twine work

- Posted in Coding by

It's not terribly difficult to implement passwording in a Twine work. First, you'd drop this into your story javascript passage:

/* hashStr - Start */
window.hashStr = function(txt) {
    var hash = 0, i, chr;
    if (txt.length === 0) return hash;
    for (i = 0; i < txt.length; i++) {
            chr   = txt.charCodeAt(i);
            hash  = ((hash << 5) - hash) + chr;
            hash |= 0; // Convert to 32bit integer
    }
    return hash;
};
/* hashStr - End */

Next, you'd need to go here (or message me and I'll help you) and use the Enter text here textbox to enter the desired password. For example, if your desired password is redrum, the hash will return -934876071 Copy that number to the clipboard, because we'll use it in the next step.

Step 3: Finally, you'll need to put the following code into a Twine passage and specify the number you got in step 2. This is a textbox where users can try to enter the correct password:

You can view the raw text here, online...

The convoluted nature of learning

- Posted in Coding by

I get a bit frustrated that I don't find myself making dazzling progress in coding works of Twine. However, I realized this afternoon while doing a lot of reading on http://intfiction.org, https://twinery.org, https://twinelab.net/twine-resources/#/, and other forums that it is this reading, interspersed with trying out snippets of Twinescript and Javascript, that make learning possible.

I know enough about learning theory to appreciate that sometimes periods of apparent non-productivity are in fact allowing the brain to percolate and make mental connections between concepts — even to have occasional epiphanies.

And so, I'll continue to read Reddit posts that are Twine-related. I'll read them trolling for valuable snippets, but also because they encourage me when I see that many other people have (1) many of the same questions I have, and (2) have creative aspirations in common with my own.

Implementation of menu system in SugarCube 2

- Posted in Coding by

The preferred way to implement menus in SugarCube 2 is to add the following code to your javascript section:

/* Trigger the following code at the start of navigation to a new passage. */
$(document).on(":passagestart", function (event) {
    /* Make sure the current passage doesn't have a "noreturn" tag. */
    if (!tags().includes("noreturn")) {
        /* If it doesn't, then set $return to the current passage name. */
        State.variables.return = passage();
    }
});

And then, tag any menu passages (however deeply nested they may be) with 'noreturn', adding the following link to those menu passages:

<<link "Return" $return>><</link>>

One possible stylesheet for a Twine

- Posted in Coding by

html { font: 100% Georgia,serif; color: #000; } tw-story { background-color: white; color: #808080; font-family: "Tahoma" font-size: 1.5em; line-height: 1.5em; }

#text_centered {
text-align: center;
}

tw-sidebar {
    display: none;
}

tw-passage a {
    color: #4169E1;
    font-weight: 700;
    text-decoration: none;
}
tw-passage a:hover {
    color: #00bfff;
}

Important notes regarding Harlowe 3 programming in Twine

- Posted in Coding by

Well, I've learned an important lesson regarding menuing in Harlowe. Don't set variables inside menu passages. I've also found some resources online including Tweego templates, SugarCube templates, etc.

I've also developed some interest in learning SugarCube, but I'm not entirely sure I have the programming chops for it.

I'm spending some time looking over [this][1] often-cited introductory material on Twine.

In the current story I'm writing, I've been able to figure out how to advance the story both by clicking on links (the hallmark of Twine) and by just clicking on or tapping the screen.

Here is the Save/Load code I'm currently using:

<div id="text_centered"><small> 
    {(link-repeat:'[Save]<saverepeat|')[
        (if: (save-game:"GameSlot1"))[
            (replace: ?saverepeat)[SAVE AGAIN!]
            (dialog: "#### Save Successful!")
        ]
        (if: not (save-game:"GameSlot1"))[
            (replace: ?saverepeat)[Save... Again?]
            (dialog: "### Save Failed...", "Bummer...")
        ]
    ]
    (link-repeat:'Load')[
        (if: (savedgames:) contains "GameSlot1") [
            (dialog: "### Loaded Save", "Yay!")
            (load-game:"GameSlot1")      
    ]
  (else:)[
    (dialog: "### No Savefile!", "Ah...")
  ]
]}
</small></div>

Local blog / site atop XAMPP-Lite

- Posted in Coding by

Why a local (offline) blog / website? So that I can be completely uncensored in my posts, and so that I can document personal or private things I don't want on the Interwebz. But also, so that (hopefully many years from now) I can leave the local blog as a curiosity piece, long-term diary, and window into my psyche, for my surviving family.

Twine, Tweego, and story formats

- Posted in Coding by

I have figured out how to use Tweego not only to produce Twine HTML stories, but also to produce proofing HTML in both the Illume (by Michael McCollum) and Paperthin formats.

I've also archived a copy of the Illume proofing format for Twine here on my Microsoft Onedrive account, and here on my OpenDrive account. Christy Tucker has an article on how to use this format at this page on her website.

Paperthin, another proofing format (and more austere than Illume) can be found on the author's Github, or here on my Onedrive, or here on my OpenDrive. Here is a sample of Illume's output.

Dotgraph is a proofing format with nice colored-nodes showing the arrangement of your twine passages. It can be downloaded here, or here, or here.

To add DeMarco's DotScap proofing format to Twine 2, we'd use https://mcdemarco.net/tools/scree/dotscap/format.js

Chapel's poof proofing format can be downloaded here, or here.

To add the PrePub format to the desktop version of Twine, we'd use this link to the format. PrePub is able to flatten simple twines to markdown in preparation for converting them to ePub format via Pandoc.

We would produce the markdown file via Twine or Tweego, and then convert to ePub in Pandoc like so:

pandoc -o my-story.epub prepub123456789.md --epub-chapter-level=2 --toc-depth=1 --css=prepub.css

I have archived a functional storyformats folder from Tweego here, here, and here.

Here are samples of the Illume, Paperthin, and Poof proofing formats.

You can use this installer to install Tweego 2 on Windows (or here on my Onedrive). There's another copy of the installer here. For my Tweego installation, I chose to put it close to the root of my main drive:

MyTweego

Notice the yellow-highlighted storyformats subfolder shown in the above screenshot.

Count directories recursively

- Posted in Coding by

How To Silently Execute a Batch File

- Posted in Coding by

Open text editor and enter this:

Set WshShell = CreateObject("WScript.Shell") WshShell.Run chr(34) & "C:\Path\To\Your\Batch\File.bat" & Chr(34), 0 Set WshShell = Nothing

Save file with a *.vbs extension and close the text editor.

Double-click the file to run your batch file silently.

This will run the batch file without displaying any output to the screen. The "0" parameter in the command specifies that the batch file should be run silently. If you want to display the output, change the "0" to "1" or "2".

Page 3 of 10