how to save each element of an array in a new line of a text file using GDScript?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Tachekentya

Hi! how can I save each element of an array in a new line of a text file using GDScript? I want each element of the array appears as a new line in the text file.

I am using the following code to do that, but what I’m getting is the whole array in one big line in the text file

func _ready():
    array_of_strings = ["a,a,a,a", "b,b,b,b", "c,c,c,c"]
    save(array_of_strings)

func save(array_):
    var file = File.new()
    file.open("res://Results//save_game.txt", File.WRITE)
    for i in range(array_.size()):
	   file.store_line(String(array_[i])) #file.store_string(content.)
    file.close()

The output now is
[a,a,a,a][b,b,b,b][c,c,c,c]

what I need
a,a,a,a
b,b,b,b
c,c,c,c

Thanks!!

:bust_in_silhouette: Reply From: Tachekentya

Use this

func save(content):
    var file = File.new()
    if (file.open("res://Results//save_game.txt", File.WRITE)== OK):
	    for i in range(content.size()):
		    file.store_line(String(content[i]) + "\r")
	    file.close()

from
https://forum.godotengine.org/30543/files-store_line-stores-all-lines-as-one-block-of-text