The docs state
prefix any method with _yarn_command_ and the runner finds it automatically.
In addition, the code sample also states
# On any node in your scene tree:
Instanced commands seem to be differentiated by the fact that you have to register them.
To that end, in the root Node2D of a scene, I placed the following function
func _yarn_command_setstate(stateName: String) -> void:
# <<setstate map>>
# Sets the current game state immediately.
match stateName:
"map":
Game.State = Game.STATE.MAP
"yarn":
Game.State = Game.STATE.YARN
pass
And called it in my Yarn script like this:
-> Tell Luke you have to go iron your cat.
<<setstate map>>
<<stop>>
However, this results in this error in the debugger
E 0:00:06:431 dialogue_runner.gd:912 @ _on_command(): yarn spinner: no handler for command 'setstate map'. Did you forget to register it? Dialogue will continue.
I also tried <<setstate "map">> only to get the same error.
When I checked the Yarn Spinner window in the Godot editor, I noticed my command had two parameters, not just one - as though the autodiscovery system counted the unspoken self parameter on the function as a parameter for the script.
This seems like a bug since I haven't explicitly tried to register the command as an instance command.
EDIT: <<setstate Node2D map>> does work.
The docs state
In addition, the code sample also states
Instanced commands seem to be differentiated by the fact that you have to register them.
To that end, in the root Node2D of a scene, I placed the following function
And called it in my Yarn script like this:
However, this results in this error in the debugger
I also tried
<<setstate "map">>only to get the same error.When I checked the Yarn Spinner window in the Godot editor, I noticed my command had two parameters, not just one - as though the autodiscovery system counted the unspoken
selfparameter on the function as a parameter for the script.This seems like a bug since I haven't explicitly tried to register the command as an instance command.
EDIT:
<<setstate Node2D map>>does work.