Read CSV GML Script

This script takes a filepath to a CSV and imports it into a DS List of DS Map values. Useful for managing large amounts of data such as calendar events, items, or dialogue.

The file makes use of another script posted previously, Explode.

///@description Returns a DS List of DS Map values from a CSV file
///@param csv

var csv = argument0;
var map = ds_list_create();

//import csv
file = file_text_open_read(csv);

//get columns
var columns = explode(file_text_read_string(file), ",");

//get rest of data
    var dataMap = ds_map_create();
    var data = explode(file_text_read_string(file), ",");
    for(var i = 0; i < ds_list_size(data); i++){
        ds_map_add(dataMap, columns[| i], data[| i]);
    ds_list_add(map, dataMap);


return map;

The final DS List looks like this:

Leave a Reply

Your email address will not be published. Required fields are marked *