Let's say I'm making a game character and each eos account is a unique character. Is there a way to mark an account with different properties like strength, speed, durability, etc....

  • yeah you can use the account name as the primary key in the contract RAM table and use the properties as fields in the struct. monstereos had something similar I think – confused00 Oct 10 at 23:06
  • link to examples? – Patoshi パトシ Oct 11 at 3:18

Yes, you can use use multi-index tables to store the relevant data in the persistent storage while indexing it by account name. To access the persistent storage, you'd need to have bought RAM to pay for the storage while it's in use.

Example adapted from the docs:

struct [[eosio::table]] mystruct 
{
    account_name    key; 
    uint64_t        strength;
    uint64_t        durability; 
    uint64_t        speed; 

    uint64_t primary_key() const { return key; } // getter for primary key
};


typedef eosio::multi_index<N(mystruct), mystruct> datastore;

Other projects such as EOSKnights show a working app using similar concepts.

  • where is this persistent storage? I thought EOS doesn't store data like this? Or wouldn't it be too expensive? – Patoshi パトシ Oct 11 at 14:25
  • yes, you need to buy RAM to have access to the persistent storage, and at the moment it's about 0.1 EOS per KiB (updated my answer to mention RAM as well) – confused00 Oct 11 at 14:30

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.