Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Rickers |
Currently I want to import all my image files at runtime, which i’ve successfully managed to store in an array.
However, I cannot seem to access ANY variable found in a singleton. I just get an error.
For example, I have a singleton pics_array.gd, here is the code for it:
extends Node2D
func _ready():
var pics = []
var a = 1
var path = "path/to/imagesFolder"
var dir = Directory.new()
dir.open(path)
dir.list_dir_begin()
while true:
var file_name = dir.get_next()
if file_name == "":
#break the while loop when get_next() returns ""
break
elif !file_name.begins_with(".") and !file_name.ends_with(".import"):
#if !file_name.ends_with(".import"):
pics.append(load(path + "/" + file_name))
dir.list_dir_end()
In my Picture_display node I have the following code:
extends Sprite
func _ready():
print(pics_array.a)
When I run this scene I get the error:
"Invalid get index “a”(on base: ‘Node2D (pics_array.gd)’).
This is really confusing me as I am following at least what I think the documentation is telling me. Also the Enable next to the singleton is checked. I even added the Picture_import scene (which has the pics_array node in it) but i’m still not getting any variable access.
I should add that i’ve already searched online but I havn’t found the answer i’m looking for yet.