Showing posts with label twine. Show all posts
Showing posts with label twine. Show all posts

Thursday, May 4, 2023

A hack to make it easier for QA Testers in Twine (Sugarcube 2)

For the game OnlyBans, we got a wonderful accessibility audit done by the Disability Sexuality Access Network. We also periodically have non-technical QA volunteers and playtesters give feedback on the game. I don't really want them to have to learn a bunch of new tools to give effective feedback and bug reports. 

Goals:

  • Testers can easily jump to/from/back to passages
  • Testers can easily reference the title of the passage they're looking at
  • Testers don't have to learn Twine or have overwhelming debug tools
  • Don't insert new content on the screen. (e.g., I can't just add the title to the top of every page
  • Make "QA Mode" something I can easily toggle on/off

To achieve these goals, I relied on adding content through the UI Bar. If your game doesn't have the Sugarcube UI bar, or if your game has complex path logic or a nonlinear history, these tactics might not be helpful for you.


1. Make a QA Passage

This passage will be a list of all the passage titles.

As far as I can tell*, there's no Sugarcube API to directly reference all the passage objects. So I instead searched all the Story objects to find objects with a non-empty passage title. Then, print that array as a link. 

!! All Pages

<<silently>>

  <<set $allPassages to []>>


  <<script>>

    var $anyRegExp = new RegExp('');

    var $passageTitles = Story.lookupWith(function (_p) {

        return $anyRegExp.test(_p.title);

        }).map(_psg => _psg.title);

    state.variables.allPassages = $passageTitles;

  <</script>>

<</silently>>

<<for _i to 0; _i lt $allPassages.length; _i++>>

<<link $allPassages[_i] $allPassages[_i]>><</link>>

<</for>>


QA Passage example 

Screenshot of the OnlyBans QA Test Passage. Header: All Passages. Below, a list of dozens of linked passages, such as "About" or "attendWorkshop"

With a few more lines of code, you could probably use the Story APIs to filter out the behind-the-scenes passages with Special Names. For example, play testers probably don't need to see the StoryInit passage listed here. 

Sometimes I'll manually add a few passages of special note. For example, during accessibility testing, I listed out a few specific passages that had complex interactions and might need special attention.


2. Make a QA mode boolean flag

In your game javascript, give yourself the nice gift of having a global variable that controls the logic of whether you want to play in the game in QA mode. 

var $isQATestMode = true;

State.setVar("$isQATestMode", $isQATestMode);


3. Add your new QA Passage to the UI Sidebar

In your StoryMenu passage (make one if you don't have one already), add a handy link to your QA Test passage. Here's what ours looks like:

[[How to Play]]

[[About]]

[[Credits]]

<<if $isQATestMode >>[[QA Test]]<</if>>


4. Display the passage name in the sidebar

In your StorySubtitle passage (make one if you don't have one already), display the name of the passage the player is currently on. That way, they can reference the correct passage if they're making a bug report. 

<<if $isQATestMode>>Current Passage: <<print passage()>><</if>>


5. Enable jumping backward & forward in time

In your game javascript file, use the handy Sugarcube Config API to make it so playtesters can go back in time. Usually I don't want my players to be able to do that.  This setting automagically adds a back button and history lightning bolt in the UI Sidebar. 

if($isQATestMode){
console.log("QA Test Mode Enabled");

Config.passages.descriptions = true;  //sets descriptions for Jump To

Config.history.controls = true; //enables back button

}
else{
console.log("NOT QA");
Config.history.controls = false; //disable backward and forward buttons

}



Screenshot with QA Mode OFF

Screenshot of the OnlyBans UI Sidebar when QA Mode is Off. The bar shows normal game content: the title OnlyBans, player stats like "Wallet $1." and player buttons such as "Settings"


Screenshot with QA Mode ON

Screenshot of the OnlyBans UI Sidebar when QA Mode is On.. The Sidebar contains a back button, forward button, lightning icon for skipping passages, and a new button named "QA Test"




What are other tricks you've used to make it easier to collaborate on Twine games? I'm especially curious for those of you with non-technical collaborators. 


*I'm usually wrong about this sort of thing, to be fair. 

Saturday, March 20, 2021

How to display media with relative links in Twine play testing mode

Twine is great, and the Twine 2 UI is a fantastic little tool for developing nonlinear stories. But as of this writing, it's great for text and not-so-great for other media. You can easily embed media using html, but it's not easy to work with as you're developing or testing your game. One frustrating note from the Twine documentation:

If you are using relative links for your multimedia, you will need to publish your story to the correct location on your computer so that the references point to the right place. If you have an image tag whose source property is “myimage.jpeg”, for example, then your published file must be placed in the same folder as the file myimage.jpeg. Learn more about relative links

If you are using relative links, testing or playing your story inside Twine will unfortunately not work.

I was using many local, relative links for images and video as I was working on OnlyBans and got annoyed enough by this to make a temporary solution for myself. To use this, you need a file syncing tool

  1. Make a media/ directory in the same location that your Twine story lives. This is likely your Twine/Stories directory. Drop your images here: Twine/Stories/images/myimage.jpg. (This step is largely for convenience.)
  2. Open your story and add an image to a story passage using an HTML tag such as <img> or <video>
  3. Test your story. You'll notice that instead of images, you'll get a little default 'missing image' icon. 
  4. Open the developer view tool for your browser. Find your image in the HTML source panel. You can often hover over the icon to locate it. 
  5. Right-click on the image name, hover over it, or open the image in a new tab to find an expanded file path. The specific filepath will vary by browser and operating system. The image below shows one way to view the expected path in Chrome. For example, on my Windows machine my browser expected to find the file at C://Users/username/AppData/Temp/Images/myimage.jpg. Our goal now is make sure that there's a copy of our image in this location. 
    Screenshot of a Twine game with a broken image link "feet-cc0.jpg". Half the screen is filled with Chrome's developer tool window. The HTML source code is displayed with "feet-cc0.jpg" highlighted. A tooltip show the full filepath, "C://Users/username/AppData/Images/feet-cc0.jpg."

  6. Open or download a file syncing tool. For Linux or people comfortable with the command line, I recommend Rsync. Right now I'm using Windows, so I used SyncFolder
  7. Sync these two folders. The source directory should be Twine/Stories/images/ and the destination directory should be the one from your browser, C://username/AppData/Temp/Images/. If syncing feels too complicated to you, you can also just manually copy and paste your images to the destination directory.
  8. Every time you add an image, alter media, change the name of a file, or close/re-open your browser, you may need to Sync that folder again. You can set up your syncing tool to run frequently, or you can manually run the sync job by pressing 'Sync' in your tool.

You might be wondering: Why not just store my images in the destination folder in the first place? That's not not ideal for two reasons. First, these temporary directories are sometimes automatically deleted by your operating system to clear up space. If you only store your images there, you may lose them to deletion! Second, when you finish your story and are ready to publish it using Twine, Twine expects to find those images in a "nearby" folder with relative paths. If you upload your media online or want to send your game to others, you will need to send them the media as well. 

Let me know if this helped you on your Twine journey, or if you have a different trick you used instead.