0

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.

1 Answer 1

0

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
});
2
  • This is great! thanks :) Commented Jun 18, 2020 at 4:28
  • Great answer, how to convert this int into human-readable format Commented Oct 21, 2022 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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