Post
Share your knowledge.
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
Answers
6To access nested struct values, write an accessor function for the child struct and call this function within the parent.
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.
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.
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.
Enums might not be supported from outside, requiring passing values as strings.
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.
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.

- 24p30p... SUI+175
1
- 0xduckmove... SUI+168
2
- Meaning.Sui... SUI+145
3
- ... SUIHaGiang+140
- ... SUIMoonBags+125
- ... SUIharry phan+100
- ... SUIJojo+61
- ... SUIOpiiii+58
- ... SUIfomo on Sui+26
- ... SUIobito+24
- Why does BCS require exact field order for deserialization when Move structs have named fields?53
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution43
- Sui Transaction Failing: Objects Reserved for Another Transaction25
- How do ability constraints interact with dynamic fields in heterogeneous collections?05