You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's assume my goal is to create a property on a base script (base.gd) that will be a reference to its own script resource. Ideally, derived nodes at an arbitrary depth in the inheritance tree will still be able to fetch the base class's resource_path to know where that file exists, and to pull other information related to that script if necessary. Creating this variable in a preferred way is proving to be impossible at the moment.
# base.gd
# Attempt 1: preloading a constant
const Base = preload("base.gd") # error, Can't preload itself (use 'get_script()').
# Attempt 2: get_script()-ing a constant
const Base = get_script() # error on the following line, Expected constant expression
# Attempt 3: get_script()-ing a var
var Base = get_script() # Works! but now if a derived class references it, it will return the derived script rather than the base type's script. Not what we want.
# Attempt 4: preloading a var
var Base = preload("base.gd") # same problem as with const. To be expected.
# Attempt 5: loading a var
var Base = load("base.gd") # this is the only version that ACTUALLY does what we want. It compiles, it works, and it allows derived types to access the base.gd script simply by referencing their Base property.
It would be preferable if this could be handled with a const and if preloading the same script were permitted.
The text was updated successfully, but these errors were encountered:
Godot 3.0 master b279f64
Let's assume my goal is to create a property on a base script (base.gd) that will be a reference to its own script resource. Ideally, derived nodes at an arbitrary depth in the inheritance tree will still be able to fetch the base class's
resource_path
to know where that file exists, and to pull other information related to that script if necessary. Creating this variable in a preferred way is proving to be impossible at the moment.It would be preferable if this could be handled with a const and if preloading the same script were permitted.
The text was updated successfully, but these errors were encountered: