Skip to content

Clarify semantics of write-only properties #1264

@sylbeth

Description

@sylbeth

As pointed out by @ttencate in #1261 (comment), there are use cases for write-only properties:

  • Setting a password, which is immediately hashed so it can never be recovered.
  • Setting a seed on a random number generator, which becomes meaningless after changing the RNG state.

These two cases can be easily done through methods, but to be fair, so can PhantomVar, but PhantomVar allows to write exported properties and link the methods together in the documentation, apart from having the very neat GDScript shorthand of calling the property or assigning to it. I believe specifically the seed one would be useful to export it for testing.

As of right now, Godot does not support write-only exported properties, generating for them a getter that returns null. I believe we can do better by generating a custom getter that returns the same as the Godot one but pushes an error or a warning. Although this could also be handled by Godot, I suppose. In any case, I thought it would be better to leave this in writing in its own issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: registerRegister classes, functions and other symbols to GDScriptquality-of-lifeNo new functionality, but improves ergonomics/internals

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions