-
I have this Go code... type Bar struct {
classdb.Extension[Bar, Object.Instance]
Message string
}
type Foo struct {
classdb.Extension[Foo, Object.Instance]
}
func (k *Bar) GetBar(message string) Object.Instance {
bar := &Bar{Message: message}
return Object.Instance(bar.AsObject())
} ...then on a GDScript I create a Foo instance and call GetBar...
...but when I run it a got this error: Reading the code I think the problem is here. This line always return true due to the previous line, so I always get If I change func (k *Bar) GetBar(ctx gd.Context, message gd.String) gd.Object { // outdated
ptr := new(Bar)
object := ctx.API.ClassDB.ConstructObject(ctx, ctx.StringName(strings.TrimPrefix(reflect.TypeOf(ptr).Elem().Name(), "class")))
object.Set(ctx.StringName("Message"), ctx.Variant(message))
ptr.SetPointer(object.AsPointer())
return ptr.AsObject()
} ...it's works as I expect. Also I'm wondering how I should write |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I would expect this to work: func (k *Bar) GetBar(message string) Object.Instance {
var result = new(Bar)
result.Message = message
return Object.Instance(result.AsObject())
} |
Beta Was this translation helpful? Give feedback.
@pafuent I have made some changes around
gd.Context
to hopefully improve the experience here, you can do the following now and I can confirm this works with the latest master: