Skip to content
← Back to Community
How to make a save function?
Profile icon
LTI2

It's the title
Anyway, i'm making a pokémon game with 24 gyms so long i guess, i need save thanks.

Voters
Profile icon
Backdoorophacke
Profile icon
LTI2
Comments
hotnewtop
Profile icon
[deleted]

A database is a good thing to use! If its in Python, well your in luck! On the side of your repl editor, you will see some database stuff here:

Screenshot 2020-09-18 at 10.04.32 PM - Edited

A quick tip for saving numbers:
Do NOT declare it. Here is an example:

from replit import db db["MyNumber"] = 0 userInput = int(input("Enter an integer:")) db["MyNumber"] += userInput #Do NOT do this, it will reset it to 0 everytime the repl starts

Do This:

from replit import db userInput = int(input("Enter an Integer:")) db["MyNumber"] += userInput print(db["MyNumber"]) # Do this! It will not get reset to 0!

I think you get the idea, anyways, hope this helps!

Profile icon
LTI2

@CarlosRosiles okay thanks

Profile icon
PattanAhmed

@LTI2 Hi,
What do you mean by function, Is it def example():?

Or it is the score or something?
If you want to store the score of the player, then you can something Database. There are lot of them but I suggest some of them like Repl DB, Mongo DB, etc.

Here are some tutorials on how to use Repl DB:-
https://docs.repl.it/misc/database
https://repl.it/talk/learn/Replit-DB/43305

Here are some tutorials on how to use Mongo DB:-
https://docs.mongodb.com/manual/tutorial/
https://www.w3schools.com/python/python_mongodb_getstarted.asp
https://www.tutorialspoint.com/mongodb/index.htm

That's it for me
Thanks!

Hope this helps

Profile icon
LTI2

@PattanAhmed like def example():

Profile icon
PattanAhmed

@LTI2 Do you want to store score in a function?

Profile icon
LTI2

@PattanAhmed yeah kinda

Profile icon
PattanAhmed

@LTI2 Ok, then.
Try using database inside a function.
There are some tutorials on how to use Database, that I have already mentioned them in the original post.
Instead of there tutorial, use them in a function.
That's it.

Profile icon
Coder100

You mean a database. I recommend using this or this

Profile icon
LTI2

@Coder100 sure i guess

Profile icon
Coder100
Profile icon
LTI2

YAY THANKS EVERYBODY YOU ALL GET UPVOTES 🎉🎉🎉🎉🎉 @CarlosRosiles @Coder100 @PattanAhmed

Profile icon
LTI2

GIVING AWAY FREE MONEY YAY jk