+1 vote

Hi

Problem 1:
Clicking and dragging a .csv file into the project file panel causes this error: ' Error importing CSV translation: 'statecode' is not a valid locale'. It also causes Godot to show the file as a red icon in the folders panel.

I have tried several .csv files and get the same problem.

Problem 2:
Changing the file postfix to .txt causes Godot not to recognise the file as it does not appear in Godot's folders panel. The following script prints "could not open file":

if file.open(filename, file.READ) != 0:
        print("opened file")
        #get_csv_line ( String delim=”,” ) 
        while not file.eof_reached():
            var line = file.get_line()
            result[str(index)] = line
            index += 1
        file.close()
    else:
        print("Could not open file")
pass

What am I doing wrong?

Thanks!

asked Feb 11, 2019 in Engine by marcorexo (85 points)

If you're using 3.0+ of the engine, you may be able to still use the files even if they don't show up in the editor. I think the editor only looks for files related to Godot, e.g. tscn, jpg, png, and json. I've been able to do this, yet the method to do that currently escapes me.

I'm using 3.2.beta4

If your CSV file does not contain translation info, you need to re-import the resource as "CSV" (default = "CSV Translation") ! The red cross will be replaced by another icon.

1 Answer

+1 vote
Best answer

You did not specify the value for filename. Either you omitted in your post or that is the problem.

I use a csv file in the project. And although there's a red cross, this file is readable.

You could however put the file in an own directory (i.e. res://data) and add a .gdignore file to that.
...but this would mean that the file will not be shown in the godot file manager and I doubt that it'll be included if you export the project. So I'd vote against using .gdignore.

Here's a part of a working code example:

var groupname=""
var file = File.new()
file.open("res://resources/data/llangollen_aqueduct_trees.csv", file.READ)
while !file.eof_reached():
    var csv = file.get_csv_line ()
        if csv.size()>=7:
                if csv[2] != groupname:
                        groupname=csv[2]
file.close()
answered Feb 12, 2019 by wombatstampede (3,193 points)
selected Feb 12, 2019 by marcorexo

Thanks wombatstampede. Appreciate your time on this.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.