Why does one work but the other doesn't?

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

So, this question isn’t too important because I found a way that works, but I was wondering why my original attempt didn’t work.

I was trying to simply print a variable from a resource but was having a lot of issues at first.
When I tried writing out that the monster var equaled the resource, like this:

onready var monster = “res://Monsters/test.tres”

it wouldn’t work and I kept getting an “Invalid get index” error. But then once I exported the monster var like this:

export(Resource) var monster

and then just dragged the resource into the var, it worked perfectly.

I was just wondering for future reference why the first attempt didn’t work. Shouldn’t both ways have gotten the same result?

:bust_in_silhouette: Reply From: timothybrentwood

"res://Monsters/test.tres" is astring variable type that also happens to be the path to the test.tres resource. You would need to load() or preload() it to use it: onready var monster = load("res://Monsters/test.tres").

Otherwise the monster variable is just a string variable no different than var monster = "hello"