Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot change existing value in a constant dictionary #71413

Closed
b0z1 opened this issue Jan 14, 2023 · 3 comments
Closed

Cannot change existing value in a constant dictionary #71413

b0z1 opened this issue Jan 14, 2023 · 3 comments
Labels

Comments

@b0z1
Copy link

b0z1 commented Jan 14, 2023

Godot version

4.0-beta12_win64

System information

Windows 10, 64 Bit

Issue description

The following code throws an error "Cannot assign a new value to a constant."

const _static = { initialized=false, config={} }

static func _initialize():
	_static.initialized = true

In Godot 3 this worked and i used it mainly for singletons. So i depend on it.
According to the documentation this should work.

Link: https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_basics.html
Statement:

Since objects, arrays and dictionaries are passed by reference, constants are "flat". This means that if you declare a constant array or dictionary, it can still be modified afterwards. They can't be reassigned with another value though.

Steps to reproduce

  1. Create an gd script
  2. Define a const dictionary with some initial values
  3. Try to change those values
  4. Error

Minimal reproduction project

See reproduction steps

@b0z1
Copy link
Author

b0z1 commented Jan 14, 2023

My guess is this MR broke it: e6c443a

@b0z1
Copy link
Author

b0z1 commented Jan 14, 2023

Okay after debugging the issue further, this MR broke it: 5e2ac1a

@akien-mga
Copy link
Member

This was changed on purpose, see #71051.

The documentation needs to be updated.

We plan to add support for proper static variables in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants