-
I have this Go code... type Bar struct {
gd.Class[Bar, gd.Object]
Message gd.String
}
type Foo struct {
gd.Class[Foo, gd.Object]
}
func (k *Bar) GetBar(ctx gd.Context, message gd.String) gd.Object {
return gd.Create(ctx, &Bar{Message: message}).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 {
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(godot gd.Context, message gd.String) gd.Object {
var result = gd.Create(godot, new(Bar))
result.Message = message
return result.AsObject()
} You should only pass uninitialised pointers to |
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: