Add support for immutable/one-time assignable variables
**Describe the project you are working on:** video game **Describe the problem or limitation you are having in your project:** I can't enforce a varriable only being assigned once **Describe the feature / enhancement and how it helps to overcome the problem or limitation:** I propose adding a new keyword to GDScript: `val` in addition to the existing `var` for declaring variables. This would force the variable to only be assigned once. Kotlin, ECMA6, and Swift all have a feature similar to this. **Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:** declaring a variable as `val` will throw a error if the variable is assigned more than once. It allows for a few nice conventions: 1) It allows for a sort of scoped constant (currently constants can only be global) 2) It prevents accidental re-assignments for varriables that weren't intended to change. It makes maintaining the code less error prone. 3) It can enforce a variable only gets assigned once in an if/else chain or match statement: ```gdscript # This is valid val x: int if foo > 2: x = 42 else: x = -5 ``` ```gdscript # This is valid val x := 42 ``` ```gdscript # This is NOT valid val x: int = 42 x = -5 ``` **If this enhancement will not be used often, can it be worked around with a few lines of script?:** Can't be worked around **Is there a reason why this should be core and not an add-on in the asset library?:** Can't, it's a language level feature
Posted by Wavesonics on May 10, 2020, 10:12 PM
Tags
Related issues
- some bike vendor told me that the biggest problem with regular to ebike conversion was that regular bike frames were not strong enough to...
- I think of this as the kiosk economy.
- What a goofy comment.
- There's lots of evidence for positive influences of Caffeine on the body (some negative as well), especially the brain.
- Compose support in WSLc
- [RFC] Roadmap to v2.0
Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments
support (Other)
some bike vendor told me that the biggest problem with regular to ebike conversion was that regular bike frames were not strong enough to...
I think of this as the kiosk economy.
What a goofy comment.
There's lots of evidence for positive influences of Caffeine on the body (some negative as well), especially the brain.
Compose support in WSLc
[RFC] Roadmap to v2.0
[Feature]: Add TurboQuant Support for KV Cache Quantization
Support for AGENTS.md and .agents/skills/, the community has been asking since August 2025
Add support for immutable/one-time assignable variables
**Describe the project you are working on:** video game **Describe the problem or limitation you are having in your project:** I can't enforce a varriable only being assigned once **Describe the feature / enhancement and how it helps to overcome the problem or limitation:** I propose adding a new keyword to GDScript: `val` in addition to the existing `var` for declaring variables. This would force the variable to only be assigned once. Kotlin, ECMA6, and Swift all have a feature similar to this. **Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:** declaring a variable as `val` will throw a error if the variable is assigned more than once. It allows for a few nice conventions: 1) It allows for a sort of scoped constant (currently constants can only be global) 2) It prevents accidental re-assignments for varriables that weren't intended to change. It makes maintaining the code less error prone. 3) It can enforce a variable only gets assigned once in an if/else chain or match statement: ```gdscript # This is valid val x: int if foo > 2: x = 42 else: x = -5 ``` ```gdscript # This is valid val x := 42 ``` ```gdscript # This is NOT valid val x: int = 42 x = -5 ``` **If this enhancement will not be used often, can it be worked around with a few lines of script?:** Can't be worked around **Is there a reason why this should be core and not an add-on in the asset library?:** Can't, it's a language level feature
Comments (0)
No comments yet. Start the discussion.