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.
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
1 Asked on January 5, 2022 by mashup
1 Asked on January 5, 2022 by coder
1 Asked on January 5, 2022 by phillip-hamnett-eos42
1 Asked on January 3, 2022 by zaigham-javed
1 Asked on January 3, 2022 by lomtax-ladamberti
1 Asked on November 24, 2021 by sachin-murali
1 Asked on November 10, 2021 by rsmets
1 Asked on August 20, 2021 by eosneedhelp
2 Asked on August 20, 2021 by josh-arnet
1 Asked on August 20, 2021 by shashi
1 Asked on August 20, 2021 by chris-de-jong
1 Asked on August 20, 2021 by artem-maluga
1 Asked on August 20, 2021 by gianmaria-toccotelli
1 Asked on August 20, 2021
0 Asked on August 20, 2021 by gary2133
Get help from others!
Recent Questions
Recent Answers
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP