Ask coding questions

← Back to all posts
How do I save a variable's value in replit's database?
OldWizard209 (1529)

No title here

Now previously, I asked JBloves to give me the source code he used to save user login data into replit's databse. He gave it to me generously. But now I am facing a problem, not with JBloves's code, but my own. And I dare not ask it on SO because I have already got like 3 downvotes on each of the 4 posts i posted in the past month and don't want to get muted for another week because SO is life you know ;).

ANYWAYS back to work.


As you can see in the repl attached, I am making a game if you can call it that lol and I am trying to save user's money in the wallet, deposited money into the db as well as the inventory. So basically, I want to save the money, deposit and inventory next to the name. So if the user is John and he has 20K in his wallet. If he signs out and logs in again, then he can see his money back.

Note: I am talking about the file in the project.

What I have tried.....

Of course I looked into the replit docs about the databse and the PyPi documentation for it , but they don't help unforunately. I don't have any idea how I supposed to save the values into the database.

And imma ping @JBloves27 for this if he can help. Please don't get angry because he seems to use database's quite often in his posts. So THANKS to anyone who can relief this burden off my head

Coder100 (18123)

You can't store dicts directly, you have to make a ref:

db["key"] = {}

temp = db["key"]
temp["b"] = 3
db["key"] = temp

say thanks to the people that forgot to fix this bug!

OldWizard209 (1529)

Lol thanks

Just a lil question.

How many languages can u proficiently program in I was wondering?

19ecal (232)
from replit import db

Is that what you want?