Hi guys, I figured out a few issues with the other plugins that i'm using, but i'm struggling with the Sheets javascript. Primarily that there are 98 different text entries in this storyline file and it would be SO time consuming to put in the javascript for each and every one.
Is there a way to change the code so that I can have one code that collects all 98 text entries at once?
I attempted this: var player = GetPlayer(); SheetsSet('UserName', player.GetVar('TextEntry53')) SheetsSet('Country', player.GetVar('TextEntry54')) SheetsSet('Occupation', player.GetVar('TextEntry55')) SheetsSet('Position', player.GetVar('TextEntry56')) SheetsSet('Gender', player.GetVar('TextEntry57')) SheetsSet('Age', player.GetVar('TextEntry58'))
as all those questions are on one slide, and it seems to have worked. But is there a modification to the javascripts for SheetSet and SheetGet that I could put on a masterslide that will just collect the rest as well as user's fill in forms on different slides?
Reply
Posted on 7/21/2024
Please type your reply.
@support
Hello.
This is really a JavaScript question, not a widget question, so the answer is also JS-focused. Your text entry variables seem to be consecutive, so you should be able to use a JavaScript "for" loop to iterate through the numbers, and also use a dictionary with the column names. Something along these lines:
var columns = ['UserName', 'Country', ...]; for (let i=53; i<151; i++) { SheetsSet(columns[i-53], player.GetVar('TextEntry'+i)); }
Take this code as inspiration only as it hasn't been tested, but in theory it should work.
There's a bigger issue with this approach that you need to consider. Google makes its Sheets API very slow by the Internet standards with every transaction taking a few seconds. So even if it takes only 2 seconds per transaction, 98 of them will need 196 seconds to complete. Are your users staying in the course for at least 196 seconds after you execute that trigger? If the answer is yes, then you're good to go.
If the answer is no, however, they will exit before all data is sent. There are two possible solutions: - Instead of using one trigger to send all data, have individual triggers on each text entry box when it changes. OR - Use Data Cloud instead of Sheets. It works exactly the same, but is significantly faster than Sheets.
Reply
Posted on 7/23/2024
@jcarpenter1986
I swapped over to Datacloud....but i think my javascript is quite off. to be fair, my javascripts are 0% basically and I used ChatGpt to generate this one after feeding it the formula for Cloudset and the general widget info.
Any idea how to tweak this to make it work?
// Function to send data to Cluelabs Datacloud using CloudSet function sendDataToDatacloud() { if (void 0 === window.CloudSet) { console.error("CloudSet function is not available."); return; }
// Loop to set 'textentry' fields from textentry1 to textentry96 for (let i = 1; i