I’m creating a game in Javascript which has a leaderboard.
I initially wanted to just have it so you can enter a player name
then click play game
.
The game has a countdown timer so I wanted to post the player score to the database in two scenarios:
- The timer reaches 0 and the game is over
- The player gets all the answers correct and completes the game
I would send an object like this:
{
name: 'Fred Smith',
score: 14
}
My question is this sensible without an actual account through register/login?
Because each time someone plays they will post a new score and name for e.g
- You set your player name to be
Bob
- You play once, it inserts a new JS object to the DB
- You click
play again
and have another game, this will post a new JS object with the nameBob
and a new score
I’m not too experienced with databases so was curious on if it would be able to manage the size, or if there is a better approach to this without implementing register/login.
Thanks
2
Answers
You can implement an unique id for each distinct user and store it as a cookie. Then use that id to store in the database.
To expand on @juliancq answer:
You can checkout the sandbox here: https://codesandbox.io/s/set-uuid-name-cookies-sw5gt3
P.S. it’s a new account so i couldn’t comment 🙂