Sui.

Post

Share your knowledge.

yhant3.
Dec 08, 2024
Discussion

How to access and manage nested structs and dynamic fields in Move?

How to access and manage nested structs and dynamic fields in Move?

  • Sui
  • Move
5
6
Share
Comments
.

Answers

6
Theoremus.
Dec 9 2024, 00:53

To access nested struct values, write an accessor function for the child struct and call this function within the parent.

4
Best Answer
Comments
.
Elvin CLONE .
Dec 8 2024, 17:05

If the Avatar struct has a generic type property like weapon: T, you need to manage the generic type's property value, like power, through accessor functions.

4
Comments
.
skywinder.
Dec 8 2024, 22:05

Dynamic fields can be attached to objects, not structs. The dynamic field module's add function requires the object's ID as the first argument.

4
Comments
.
Pluto Dev👽.
Dec 8 2024, 05:47

An approach to access generic child struct values involves creating an enum, saving it in a property on the parent struct, and referencing the enum to call the appropriate module getter.

3
Comments
.
YJS.
YJS200
Dec 8 2024, 08:51

Enums might not be supported from outside, requiring passing values as strings.

1
Comments
.
Dominikus .
Dec 8 2024, 22:00

There's no direct way to type convert generic types within an object in Move. A workaround involves adding different Weapon types and creating a Weapon struct.

1
Comments
.

Do you know the answer?

Please log in and share it.

Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.

306Posts450Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

Gain Reputation Points & Get Rewards for Helping the Sui Community Grow.

Reward CampaignJune
We use cookies to ensure you get the best experience on our website.
More info