Skip to content

How should I instantiate a Go struct to return it in a method and then use it on GDScript? #35

Answered by Splizard
pafuent asked this question in Q&A
Discussion options

You must be logged in to vote

@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:

func (f *Foo) GetBar(message gd.String) gd.Object {
	var result = gd.Create(f.Temporary, new(Bar)) // temporary reference.
	result.Message = message.Copy(result.KeepAlive) // keeps the copy alive for the lifetime of 'result'
	return result.AsObject() // godot gains ownership of the object.
}

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@pafuent
Comment options

@pafuent
Comment options

@Splizard
Comment options

Answer selected by Splizard
@TeddyDD
Comment options

@Splizard
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants