Problem running a text parsing method

Hey there Playcanvas Community,

I am currently trying to setup part of my game so that I can get strings and values from a google sheet via URL.
The thing is that on the one hand, I am spoiled by unitys WWW class, on the other hand I do not manage to get regular .split functions running, nor can I find any clues as to whether or not options like that even exist for PC.
So before i go out there and write my own splitter, please see if you find a step where I went wrong ( or if I am simply retarded ), or if there is an option that I am overseeing.
Thanks in advance!

My current state is below, and just tells me that split is not a function.

var QuizMaster = pc.createScript('QuizMaster');

QuizMaster.attributes.add("sheetURL", {type: "string"});

// initialize code called once per entity
QuizMaster.prototype.initialize = function() 
{
    this.textContent = 0;
    this.lines = 0;
    this.lineContents = 0;
    this.URLcontent = pc.http.get(this.sheetURL, function(error, response) 
    {
        console.log("response says : " + response);
        this.textContent = response;
    });
    
    this.ParseSheet();
};

QuizMaster.prototype.ParseSheet = function()
{ 
    this.lines = this.textContent.split("\n");
    for (var i = 0; i < this.lines.length; i++)
    {
        console.log(this.lines[i]);
        lineContents = this.lines[i].split(",");
        console.log(this.lineContents[i]);
    }
};

It’s possible that the response from the get is an object rather than text.

Going through the debugger will help here.

Do you have an example project that we can look at?

this is the project:
https://playcanvas.com/project/593701/overview/a-nurse-for-serious-business

Ah, I did check the result out in the console and figuered it would serve the purpose for now (does indeed give way too much info about the object).
So you suggest that .spit does not work because the variable it is called from is not a string but an html object (or something like that) and thus doesnt access the methods for strings?
Please correct me on anything wrong here, quite new to javascript and these flexible variables.

I will see if I manage to understand the .get to only give me the actual text of the sheet.

Ah, from what you suggested I tested if split works with regular strings and it perfectly does, so cheers to my bonobo brain for not thinking about that.
So back onto the .get for now ~

I’ve had a quick look and realised that your callback closure for the get request is using this in the wrong scope.

In JS, closures don’t bind the this pointer automatically to the class instance. The general workaround is to use self as I have done.

https://playcanvas.com/editor/code/604363?tabs=17849009

The other problem is that you are using a standard link to the Google Sheet which will give you the HTML data and not the CSV that you probably were expecting.

I recommend either moving the questions directly into the game code or use this article to get the sheet data as a JSON. https://coderwall.com/p/duapqq/use-a-google-spreadsheet-as-your-json-backend