Twine Load Data Script


  • Platform: Twine / Google Sheets
  • Programming Languages: JavaScript, Google Sheet Script, HTML & CSS
  • Developers: Only Me

Relevant Links


Are you looking for a google sheet script that allows you to save and load data into cells on a google sheet for use in a Twine game? Found this page? The work completed here was for a client and is not 100% publicly available. I am happy to release this code to people who need it on request, use on the contact page or email and will get back to you ASAP.

Version 1 – March 2020

This was a client project, the client was working on a twine ‘proof of concept’ for a simple story game that would ask the user to enter a work which would be saved into a google sheet when entered, or enter a default value when no word was entered. The client was using a pre-exsisting script that was a little out-dated. The script still worked when sending the data, but the loading of the data was not working. My job was simple, make a functional loading system for the game.

I worked on this over a few evenings in-between my university work, while it wasn’t an urgent project and didn’t need finishing for a while, I felt it best to get it done so I wasn’t juggling projects. I spent most of my first evening getting my head around how the exsisting Javascript & JSON worked, as the closest I’d worked on before was HTML & C#.

On the second evening I was able to return a word to the game project and by the third I had it working for a list of words. While I was at it I added a randomiser method that would choose 10 random words (10 was the requested amount by the client) and not repeat a cell once it had been selected by the load request. I then added a simple javascript to the project where the data was meant to be displayed. As well as a loading text area that would disable when the data was ready to be shown. Just listing them was all that the client needed for the POC.

I did later remark on missing features that would allow for all user cases, such as multiple users that entered the same word showing up more than once on the display. However the client was not fussed about having these as the POC only needed to show the game saving and loading what was entered.

This project certainly was a challenge, but also a nice change of pace. Having to learn new code languages on the fly and get results quickly was fun and I’d happily do it again.

Version 2 – June 2020

A few months after the initial solution was completed, I was contacted again to see if some changes could be made in order to allow the game to load words for a different columns as needed. This needed a rather large rework as the script would need to save to a defined column on the google sheet and then be able to read a column based on a parameter passed through the get method.

I went about getting the ability to send data sorted first. Fortunately this was a simple process, only needing to pass through and read a parameter to tell the script which header to place under. The rest was already there and nothing else needed altering.

I then had to do the same for the return method which was a lot harder. This was not helped much by the lack of tools to debug the code, as google sheet script kind of assumes it meant to only run on its own platform. Because of this I spent most of my time trying to figure out what was and was not working. I eventually figured out that some of the methods I was using from my last iteration were not running or working as intended. Because of this I decided to remake them and, at the same time, improve the script so it would do extra checks to remove blank entries and duplicates as well as displaying an output even if the sheet did not have enough entries to show.

The final product this time around was far better than the previous version and worked perfectly for the client, who was delighted with the extra work done to it. The code for this version is available on request, note you may be charged a small fee to licence the work.