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.
- yhant3235How to access and manage nested structs and dynamic fields in Move?56
- deriss82How to convert private key to new format via CLI33
- elfDani176Can you export an official Sui wallet to Razor or other Sui wallets?32
- Xavier.eth223'DataClone Failed to execute' error33
- yhant3235How can I claim Deep tokens if I have a DeepBook NFT?32