How do I create a get function to return an array with elements of user defined type

I’ve been trying without success to work out how to write functions that return arrays whose members are of a user defined type. I’ve tried every plausible construction that I could think of, so can anyone kindly point me in the right direction?

You might use MotokoPlayground in the future when you have such a question.

Makes it a lot easier for someone to provide a usable answer.

Seems like someone else is answering so I’ll let them actually answer.

1 Like

Buffer is unbound type cause it has functions inside it, the array you defined on the other hand has a type with variable fields and for some reason those can’t be used in shared functions.

So what you need to do is either make them immutable or create a different type, usually it’s advised to work with Buffers and turn them into an array when you want to store the data in stable memory or return it.

Got it, thanks. I’ll try making them immutable.

Thanks for the advise. I’m just getting my bearings and appreciate the direction.