+1 vote
by (530 points)
edited by

Hello all!

I'm currently doing a project for an upcoming university showcase and was hoping to make it so that I could collect and save the variable inputted by the player through the prompt macro, so that it would be uploaded and saved to a google sheet and then, a passage later, for that piece of data and the ten of so pieces preceeding it to be displayed so that the player can see some other responses.

However, I've run into a bit a of snag in coding the data upload. I've followed the guide as per John Stewart (http://www.johnastewart.org/coding/twine-game-data-to-google-sheets-via-javascript-version-2/) and followed it word-for-word. I then published the file and ran it on my browser but the upload didn't work.

I would appreciate any ideas as to if it's a version issue or if it's just a problem with my coding.

Current code is this:

//in the javascript section

if (!window.harlowe){
    window.harlowe = {"State": State};
}

 

//in the prompt passage

(set: $word to (prompt: "What is the Castle to you?", "Type here!"))

 

//in the penultimate passage

<script src="jquery-3.3.1.min.js"></script>

<script>

var sendData = JSON.stringify({
"word": harlowe.State.variables['word']
});

$.ajax({
url:"https://script.google.com/macros/s/AKfycbypqjLgC5tAmJPez9ad4hXwDsBWmfQQYr76GKAGzDKqCi9UBAfk/exec",
method: "POST",
dataType: "json",
data: sendData
}).done(function() {});

</script>

 

The Google Scripts code was copied directly from John Stewart's blog post so that should all be correct and I've changed the var = SHEET_NAME = "...."; with the part in speech marks changed to match the Google Sheets title. The Google Sheets is also set so that anyone with the link can edit the sheet, even anonymously.

Would appreicate any help!

 

Thanks,

The Tame Historian

1 Answer

0 votes
by (44.7k points)
selected by
 
Best answer
Does your sheet have a column named "word"?

If that doesn't fix it, a link to the sheet might help.
by (530 points)
by (44.7k points)

Ah, the problem is that you've confused the name of the document for the name of the sheet in the document.

In the script editor, change:

        var SHEET_NAME = "Twine_Castle_Game_Data";

to:

        var SHEET_NAME = "Sheet1";

(the name on the tab found at the bottom of the document)

Hopefully that should do the trick!

by (530 points)
Thank you so much!

It's now working perfectly (it's always a little thing isn't it!)
...