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
The line below creates a CONST property pointing to a new empty dictionary:
const SSSM_GLOBAL_BLACKBOARD: Dictionary = {}
The following behaviors apply, and can be confirmed with simple testing in a regular script:
A const dictionary can start empty or populated. In both cases, you can later add, change, remove keys and values at will.
Once you have defined a const Dictionary property, you cannot later assign it a null value or another dictionary object or a new empty dictionary object. All three actions will throw an engine error, as expected.
HOWEVER, if you include your const dictionary property in an autoload script, the engine will throw an error when you attempt to do anything with that dictionary's contents. The error is "Invalid set index ... ". For example, attempting to add a new keypair to the empty dictionary. Oddly, it does actually add the keypair to the dictionary (confirmed by inspecting the dictionary object at runtime) and only after that throws the error, suggesting this is not intended behavior
What is it about autoloads that change the behavior of a const dictionary? They are nodes in the tree like any other, so I would expect the behavior to be the same as having the const dictionary in a regular node script.
Run project and observe the error (see the godotforums link earlier for screenshots).
Remove the Globals.gd script from autoloads and copy the "const SSSM_GLOBAL_BLACKBOARD" property to your Node2D script. Alter the "Globals.SSSM_GLOBAL_BLACKBOARD" to "SSSM_GLOBAL_BLACKBOARD". Run the project and observe that no error is thrown.
Minimal reproduction project
See above for simple repro steps.
The text was updated successfully, but these errors were encountered:
Godot version
3.5.1-stable
System information
Linux
Issue description
See here for background: https://godotforums.org/d/32258-const-x-dictionary-not-working-in-autoload-script-cannot-assign-to-it/3
The line below creates a CONST property pointing to a new empty dictionary:
const SSSM_GLOBAL_BLACKBOARD: Dictionary = {}
The following behaviors apply, and can be confirmed with simple testing in a regular script:
A const dictionary can start empty or populated. In both cases, you can later add, change, remove keys and values at will.
Once you have defined a const Dictionary property, you cannot later assign it a null value or another dictionary object or a new empty dictionary object. All three actions will throw an engine error, as expected.
HOWEVER, if you include your const dictionary property in an autoload script, the engine will throw an error when you attempt to do anything with that dictionary's contents. The error is "Invalid set index ... ". For example, attempting to add a new keypair to the empty dictionary. Oddly, it does actually add the keypair to the dictionary (confirmed by inspecting the dictionary object at runtime) and only after that throws the error, suggesting this is not intended behavior
What is it about autoloads that change the behavior of a const dictionary? They are nodes in the tree like any other, so I would expect the behavior to be the same as having the const dictionary in a regular node script.
Steps to reproduce
Start a new 2D project.
Create a new Globals.gd script:
Add the script to the project's autoloads.
Create new Node2D off root. Add to it this script:
Run project and observe the error (see the godotforums link earlier for screenshots).
Remove the Globals.gd script from autoloads and copy the "const SSSM_GLOBAL_BLACKBOARD" property to your Node2D script. Alter the "Globals.SSSM_GLOBAL_BLACKBOARD" to "SSSM_GLOBAL_BLACKBOARD". Run the project and observe that no error is thrown.
Minimal reproduction project
See above for simple repro steps.
The text was updated successfully, but these errors were encountered: