Topic was automatically imported from the old Question2Answer platform.
Asked By
givenmnisi6
I’m writing a method (function to read from a file), and I get this error: Could not find type “File” in the current scope and Identifier “File” not declared in the current scope.
Here is the code :
func loads(num: int) → void:
var poemTitle: RichTextLabel = $Title
var poemText: RichTextLabel = $Text
var txtFile: File = File.new()
if !txtFile.file_exists("res://Poems/" + story[iStory] + ".txt"):
poemText.text = "Story not found"
return
I get this error: Native class “FileAccess” cannot be constructed as it is abstract., Static function “new()” not found in base “FileAccess”.
Here is the code below:
var poemTitle = get_node("Title") as RichTextLabel
var poemText = get_node("Text") as RichTextLabel
var txtFile: FileAccess = FileAccess.new()
if !txtFile.file_exists("res://Poems/" + story[iStory] + ".txt"):
poemText.text = "Story not found"
return
txtFile.open("res://Poems/" + story[iStory] + ".txt", FileAccess.READ)
givenmnisi6 | 2023-06-12 17:56
Check the docs linked above by @HyperlinkYourHeart. It contains some very simple examples of a file read operation…
jgodfrey | 2023-06-12 18:00
Okay, I will do so. Thank you so much for the help.