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.

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
});
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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