0 votes

Hi,

First test

When I try this script all the lines adds as item in the dropdown list 26 times. What am I doing wrong?

extends OptionButton

onready var file = 'res://bilhandtering.txt'
func _ready():
load_file(file)
func load_file(file):
var f = File.new()
f.open(file, File.READ)
while not f.eof_reached():
    var line = f.get_line()
    for item in line:
        add_item(line)
f.close()
return

Second test

When I use csv below the dropdown list gets populated ok except for that there is a space gap of 32 options and then it repeat the first items in the csv file.

extends OptionButton

var LevelFileName="res://bilhandtering.csv"

func _ready():
var riga = []
var csv=File.new()
csv.open("res://bilhandtering.csv",File.READ)
riga=csv.get_csv_line(";")
while not csv.eof_reached():
    for item in riga:
        add_item(item)
    riga=csv.get_csv_line(";")
pass
Godot version 3.2
in Engine by (16 points)

Please show and examplse of the csv and or txt

as it looks like you're using the for loop redundantly and it should be like this but hard to say without knowing how your files are structured

while not f.eof_reached():
    var line = f.get_line()
    add_item(line)
f.close()

Thanks Wakatta your solution worked for the txt file, the struckture of the txt file is line by line.
The for item in line: made the repeted input-

Please log in or register to answer this question.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.