Circular Reference in Adventure Game

Hi guys, I’m creating a text-based adventure game in python and I’ve tried to use the replit database functions to store data for players using usernames and passwords to identify the save to load.

I’m using the username as a key to search through the database and select the correct record. However, when I try to save my player objects attributes (which includes other objects and their attributes) in a list, I get a ‘circular reference detected’ error.

I’ve searched my code to find the problem or where I’m importing incorrectly but can’t find it. The code is abit messy as I’m not the most clean programmer but any help would be appreciated, thanks.

Here’s the link for the code:

I have actually come across this error before, and although I have not looked at the code, last time it was because I was trying to set a non json serializable object to the db. Probably because of poor design, the error given is completely unrelated.

How did you go about fixing it?
Did you redesign the whole code or is there a way to make objects that can be json serializable?

Turn them into a dict. Use classname.__dict__ on all the classes that you are trying to set. It turns the class into a json serializable object.

Are you trying to store usernames & passwords locally or…

1 Like

Yeah, I’m trying to store them locally

which file returns the error

1 Like

It’s in when I try to pass the objects from the player object into the database

Where would I put this line of code, would it be after creating the classes, in another file or would i put it when creating the classes

You would put it when saving to the db. I can’t really tell you more, as your code is untyped and therefore hard to understand for others.

When I try to do this, I get an error saying that ‘mappingproxy’ object is not callable

Im struggling to understand what file does what.

Yeah, sorry it is very messy, I haven’t really coded anything for other people so see before so there’s not many comments

Full error please. (It tells us where in the code your error stems from)

Heres the full error, Ive had to put it as a screenshot as i cant copy and paste for some reason

Don’t call it, just do __dict__ without the ()

1 Like

Im getting a circular reference again

I think i might have to do it for some more classes

1 Like

Its still giving me the circular reference error. I have to go but if you guys do find anything it would be great to know.

Thanks for all the help and sorry about the messy code once again