Read text file when choosing item from OptionButton

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Andrej Poženel - SDT

Hello!

I have a question about reading file by GDScript. So i have a custom text file with my personal file extension, and in my project scene i have set two labels and one option button named dropdown.

So i want to change the text on both labels respectively, when user selects different item on dropdown.

I have set the signal and script in this way:

extends Control


onready var bg = $bg
onready var dropdown = $Dropdown
onready var aNt = $"authors&title"
onready var lyricsarea = $lyrics
onready var backbtn = $back






func _on_Dropdown_item_selected(ID):
	
	
		
	if ID == -1:
		aNt.text = "Razorlight - Wire to Wire"
		lyricsarea.text = ""

	elif ID == 0:
		aNt.text = "NOTHING TO SEE HERE, ONLY FOR BLANK SCREEN"
		lyricsarea.text = ":)"
	elif ID == 1:
		aNt.text = "test1"
		lyricsarea.text == "test1"
	elif ID == 2:
		aNt.text = "test2"
		lyricsarea.text == "test2"





func _on_back_pressed():
	get_tree().change_scene("res://MainMenu.scn")
	
	

In fact i am working on Lyric application, that displays lyrics of the song, when user selects one from OptionButton (dropdown) menu.

Now i have two options:

First one is that i create text file for each lyrics of the song and then read it back in on demand, when user clicks on appropriate item

OR

Second one, that i embed lyrics in the code itself, which i just tried, bot nothing happens, when i run it…

Note that this is not a very serious project, just something for learning and teaching myself.

What is better to do: First or Second option?

And if you can correct my code, because i spent all day trying to figure out why it won’t work as expected… it does not even work…

:bust_in_silhouette: Reply From: Noah Burck

It would make much more sense to load the lyrics from a separate text file. That way, you could hypothetically set the program up to scan the directory with the files and access lyrics from all of them.