migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.14k stars 76 forks source link

Cannot export a variable with name "value" #363

Closed Airyzz closed 9 months ago

Airyzz commented 9 months ago

I am updating my project to the latest version of SwiftGodot, and have run in to this issue.

In my project, I have some custom resources which simply exports some value:

@Godot
class IntResource: Resource {
    public var hasChanged = false

    public var innerValue: Int = 0

    @Export
    public var value: Int {
        get {
            if hasChanged {
                return innerValue
            }
            return defaultValue
        }
    }

    @Export
    public var defaultValue: Int = 0
}

This is no longer possible, as the code generation for this export redefined 'value' to be a let:

func _mproxy_set_value (args: [Variant]) -> Variant? {
    guard let arg = args.first else {
        return nil
    }
    if let value = Int (arg) {
        value = value
    } else {
        GD.printErr ("Unable to set `value` value: ", arg)
    }
    return nil
}