How to save user stats

Question:
How do I make it so that users can save their game stats, exit, and come back and it still be saved.
https://cookieclicker.killercl0wn.repl.co/

code snippet

oh.
Do this:

from replit import db,clear
try:
  print(db['test']);clear()
except:
  db['test'] = 1

with this try and except statement, it checks if the player has ‘test’ in the database, if it does not have it in the database, then it creates one for them. But if they do have it, it will print it out and clear the screen.
heres how you can save it:


# a bunch of code here..
test = db['test']
test = 2
def save():
  db['test'] = test
save()
1 Like

You could use localstorage for this, but it can be changed. Try using a backend.

2 Likes

I have made a game that stores the user’s game data and loads it back later. You can see it here: https://replit.com/@NateDhaliwal/Jackpot
The game uses ReplitDB.

How would I do that? I’ve been learning a lot from these projects and it’s always nice to learn from someone experienced.

1 Like

wanna take a look at my code and see if you would be able to transfer it to a db?

Sure! Can you send me the code and not the link to your project? It’s easier to navigate and read.
Sorry for the inconvenience.

https://replit.com/@KillerCl0wn

you can use this to get there I don’t know how to send you a link that goes directly to the code

You can copy and paste the code here but nvm.

Can you send me the link to your project? Thanks so much.

like invite you to it?

No need. Just the link.

https://cookiecrusher.killercl0wn.repl.co/

I code mainly in Python, so if you want me to integrate ReplitDB into another language it may take me a while.

K i need it in JS. You can fork my program then tell me when your done

Is it possible to send the project’s link and not the website?

I don’t think so. Fork it and you’ll be able to see it all

I can’t fork it from the website.

You may have to get someone’s help and not mine if you are using JS. Maybe @OmegaOrbitals can help.

https://replit.com/@KillerCl0wn

on the programs on display click the left arrow twice and you’ll see it