Twine scripts and macros

catdance2

NOTE: Material in this tutorial does NOT work with Twine 2’s default format, Harlowe.

Scripts allow you to add new features to your Twine game. You can find these scripts posted on blogs and in Twine forums. For example, Leon Arnott has created many scripts and has posted them to his blog, Glorious Trainwrecks.

To add a script to your game, click the menu in the bottom-left, then click Edit Story JavaScript. Copy and paste the script from the blog into the Edit Story JavaScript passage. Here is a simple script that I created that will allow you to change the background image within passages:

//changes the background image
macros['setback'] = 
{
handler: function (place, macroName, params, parser) {
document.body.style.backgroundImage = 'url('+params[0]+')';
}
};


Screenshot 2014-05-13 11.07.31
Screenshot 2014-05-13 15.21.17After adding that, you can use the macro <<setback>> on any page in which you would like to change the background image. Be sure to include the URL for the image. Like this:

<<setback http://ohiofi.com/img/oh.png>>

<<setback http://ohiofi.com/img/oh.png>>

Finally, you might want to include some CSS like this:

body {
background-repeat:no-repeat; background-size:100%;
}


Here is a DEMO that uses my setback macro.
Screenshot 2014-05-13 16.10.03
mario
This is part of a larger “How To” guide, click here for my full How To Use Twine guide.

CONTINUE TO THE NEXT POST: How to use Google Drive to store High Scores for Twine games

Comments are closed.