Preload function would have to accept a constant string parameter as input.
const WARM_UP_STATE = "res://scenes/states/warm_up/warm_up.tscn"
func _go():
current_state = preload(WARM_UP_STATE).instance()
level.add_child(current_state)
res://scenes/levels/level_01/src/node2d_state_manager.gd:23 - Parse Error: expected string constant as 'preload' argument.
Not understanding what you mean.
you could just do:
WARM_UP_STATE = preload("res://scenes/states/warm_up/warm_up.tscn")
then just call it in your function
func _go():
current_state = WARM_UP_STATE.instance()
level.add_child(current_state)
That's right! But IMO it doesn't change the fact that the function should accept a constant string and WARM_UP_STATE is a constant string.
I also think it should accept constants even if it's defined in external file (lets say I have singleton with constants)
This is amusing. I was going to say something because I am loading an "empty scene" from a string constant in my project. Turns out I was using load() (which works) instead of preload() (which doesn't), making them inconsistent.
Well it's normal that load() works as it does not expect a constant. But preload() does, and apparently fails to see a const String as such.
Ah I see, I figured load() would also expect a constant.
As i see it, preload function loads the resource when the scene is constructed, for that reason needs a constant input, on the other hand load function loads the resource when it is called.
Most helpful comment
I also think it should accept constants even if it's defined in external file (lets say I have singleton with constants)