GML Reading CSV Files

Posho

Member
Hello.

I am working on a project that needs to handle lots of database data. I manage all this data on Google Sheets and then export it as a .csv file which then the game would load and save as either an array or ds_grid.

My problem here is that I haven't found a single method that actually works. I spent my entire afternoon looking and downloading examples that don't work or use outdated functions. Even the info on the Help/Docs section for csv_load uses non-existing functions, so I'm asking for help here as a last resort.

Any suggestions? I'd seriously appreciate it.
 

GMWolf

aka fel666
Hello.

I am working on a project that needs to handle lots of database data. I manage all this data on Google Sheets and then export it as a .csv file which then the game would load and save as either an array or ds_grid.

My problem here is that I haven't found a single method that actually works. I spent my entire afternoon looking and downloading examples that don't work or use outdated functions. Even the info on the Help/Docs section for csv_load uses non-existing functions, so I'm asking for help here as a last resort.

Any suggestions? I'd seriously appreciate it.
well, the function name os load_csv, not csv_load. And i think its only available in GMS2.
 

Alexx

Member
I also fancy having a bash at making a script for this.
Do you have a sample CSV file I can work on?
 

Posho

Member
If you're open to using JSON, you can use this program to convert the csv into a JSON file. Only option you really need to check is "First row is column names"

http://www.convertcsv.com/csv-to-json.htm
Holy moly! I didn't use the JSON file handling, but there's a template builder on that website.
http://www.convertcsv.com/csv-to-template-output.htm

Basically, I set up a template then imported my CSV file and the website automatically outputs a text I can simply paste on my GML code like:
Code:
array[0,0] = this;
array[0,1] = that;

array[1,0] = et;
array[1,1] = cetera;
My project is for my own personal use only so it's not important if it doesn't have a fancy file handling system. I actually used to do something similar by importing Microsoft Excel values into Microsoft Word and then automatically arrange it as GML code, but since I don't have (and really don't want to install) Microsoft Office anymore I instead considered doing it the efficient way with proper CSV file systems.

This seriously helped me, man! Thank you, thank you! Though would I still want to check @Juju's script so maybe later I can do this the actual right way.

I also fancy having a bash at making a script for this.
Do you have a sample CSV file I can work on?
CSV files stand for "comma separated values" and you can write them in programs like Microsoft Excel or Google Sheets and then save them as a .csv file, and it would look something like this:
Code:
character,weapon,hp
mage,staff,200
rogue,knife,40
paladin,great sword,9999999
 
Top