Last updated: 22 May 21 00:37:31 (UTC)
Creating Twine variables from Google Sheets cells
Accomplished while creating the ELC4 author form (Weblink).
At its core, this method has to do a few things.
-
It has to take the passcode from the user (or any other bit of data that can correspond to a row or other element of G-sheet) and create a Javascript variable from it. I found a way to do this with document.getElementById.
-
It has to dynamically update the G-sheet QUERY for each desired data item in the row matching the passcode.
-
It has to create a TWINE-usable variable for each of those data items.
-
The variable has to be trimmed: strings from G-sheet cells are encoded in table-row and cell html tags, which can really throw stuff off when using them in Twine, and when feeding them back into G-sheets (as necessary).
(In Twine) Story Javascript & Log-in Passage
- Set up Sheetrock according to Log-in Page that Pulls codenames IDs from Google Sheet (Weblink).
- KEY DIFFERENCES:
- In the log-in page, instead of using Twine’s *textbox *function for passcode entry use an html input box. The javascript doesn’t seem to want to read the Twine variables, but it will read the id of this html input box.
- This also means that in the “submit” button, you must use the JS “getElementById” to create the Twine variable.
- Included my now-standard “wait for Google to respond” repeat sequence because slow internet speeds can return undefined $response variables.
Please enter the code:
<<button "Submit”>>
<<repeat .5s>>
<<if $response != undefined && $revCk != undefined>>
<<set $code = document.getElementById(“code”).value>>
<<if $code == “”>>
<<replace “#textbox-reply”>>
Please enter your code.
<>
<<elseif response.includes(code)>>
<<goto [[currentInfo]]>>
<
Incorrect. Please try again.
<>
<>
<
- So-named because in the ELC4 author form, I used the next passage after log-in to fetch the user’s information from the G-sheet according to the passcode they had just entered.
- If a passcode isn’t used, and there is no need to have dynamic information in the query strings, this can go in the Twine’s Story Javascript instead of an individual passage.
</g, ‘’);
var title = t2.replace(/</td></tr>/g, ‘’);
State.variables.title = title;
}
});
$(“#date”).sheetrock({
url: mySpreadsheet,
query: dateQ,
callback: function (error, options, response) {
var dt1 = response.html;
var dt2 = dt1.replace(/ /g, ‘’);
var date = dt2.replace(/</td></tr>/g, ‘’);
State.variables.date = date;
}
});
});
<>
<>
table row/cell opening and closing tags from the string fetched from the GS cell (for some reason, it always returns with these). and