AnswerBun.com

How to add current date and time in the table so we know when a game score was logged?

EOS.IO Asked by Ramesh Gopal on August 20, 2021

For a gaming leaderboard. players will be able to compete with each other through a leaderboard.

When a new score is added, it is inserted in to a table that is scoped to the game
Each game is limited to the top 10 scores, so when a new score is added, one has to be removed if there are already 10 items. This should also add the current date and time in the table so we know when a game score was logged.

One Answer

You can use eosio::current_time_point() to get time in microseconds in smart contract.

#include <eosio/system.hpp> //include system header

uint32_t now() {
   return (uint32_t) (eosio::current_time_point().sec_since_epoch());
}

Add a scoreTime field in your score table

struct [[eosio::table]] table {
   uint32_t scoreTime; //add scoreTime in your table
   .
   .
   //other table fields
};

Add score time while inserting new score in your table.

table.emplace(get_self(), [&]( auto& row ) {
   row.score = 10;
   row.scoreTime = now();
   .
   .
   //other table fields
});

Answered by Abdul Moiz on August 20, 2021

Add your own answers!

Related Questions

What is the difference between std::string and eosio::string?

1  Asked on January 5, 2022 by phillip-hamnett-eos42

   

How to use scatter without node.js?

2  Asked on December 11, 2021

 

Ico smart contract update

2  Asked on November 22, 2021 by efraim

   

How does one print an iso timestamp in a smart contract

1  Asked on August 20, 2021 by chris-de-jong

 

can’t generate abi when using map

1  Asked on August 20, 2021 by vishal-singh

   

Action setprods on EOSIO v2.0 private chain

2  Asked on August 20, 2021 by scott-owen

 

How to unstake ALL my EOS from EOS Voter Greymass

1  Asked on August 20, 2021 by gianmaria-toccotelli

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP