How do I store quotation marks in an array?

0 favourites
  • 4 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I'm working on a game that has dialogue in it. I put the dialogue (and some other data I need) into an Excel sheet and export it to a JSON file.

    Then I import this file into Construct 3 and convert it to an array.

    Unfortunately, I ran into an issue with the quotation marks. I solved it -- for now -- by using single quotation marks "'" but this makes the dialogue harder to read.

    How do I store quotation marks in an array? With triple quotation marks? For example: """.

  • It's easier to use Array Editor in C3, it's very similar to Excel. And I'm pretty sure you can store quotation marks as they are, no need to double or triple them.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I made an example of this before, Convert CSV to JSON via JavaScript. You can export as a CSV file in Excel. Then convert to JSON in C3.

    CSV to JSON

    cdn.discordapp.com/attachments/225550155531812865/1091824119928078457/CSVtoJSON.c3p

    Another example JSON Branch Dialogue System

    cdn.discordapp.com/attachments/225550155531812865/1092398948607598672/JSON_BranchDialogueSystem.c3p

    ---

    and save them with their header as Key. if they have the same ID, they are stored as an array.

    ID,Name,Text
    Screen1_Intro,Alice,Hi!
    Screen1_Intro,Bob,"Hi, Alice! How are you today?"
    Screen1_Intro_A1,Alice,That's great! What are you up to today?
    Screen1_Intro_A2,Alice,"I'm okay, What about you?"
    

    Convert to JSON:

    {
     "Screen1_Intro": [
     {
     "Name": "Alice",
     "Text": "Hi!"
     },
     {
     "Name": "Bob",
     "Text": "Hi, Alice! How are you today?"
     }
     ],
     "Screen1_Intro_A1": [
     {
     "Name": "Alice",
     "Text": "That's great! What are you up to today?"
     }
     ],
     "Screen1_Intro_A2": [
     {
     "Name": "Alice",
     "Text": "I'm okay, What about you?"
     }
     ]
    }
    

    Here is the code to convert csv to JSON.

    Create a new js file in the Scripts folder and paste it in. Note that this Script properties need to set the Purpose to 'Imports for events'.

    function csvToJson(csv) {
     const lines = csv.split("\n");
     const headers = lines[0].split(",");
     const result = {};
    
     for (let i = 1; i < lines.length; i++) {
     const currentLine = lines[i].split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/);
     const obj = {};
     for (let j = 0; j < headers.length; j++) {
     const header = headers[j];
     const value = currentLine[j] ? currentLine[j].replace(/^"|"$/g, '') : '';
     if (header !== headers[0] && value) {
     obj[header] = value;
     }
     }
     if (Object.keys(obj).length) {
     const screen = currentLine[0].replace(/^"|"$/g, '');
     if (!result[screen]) {
     result[screen] = [];
     }
     result[screen].push(obj);
     }
     }
    
     return JSON.stringify(result);
    }

    It's also very easy to use in C3.

  • Thanks for the excellent replies. I wanted to provide a quick update because I found a problem with my VBA export tool. (It was an issue with how JSON was handling quotation marks.)

    I fixed the problem by adding three slashes "\\\" in front of each quotation mark (in the JSON file).

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)