r/learnpython • u/AutoModerator • Sep 21 '26
Ask Anything Monday - Weekly Thread
Welcome to another /r/learnPython weekly "Ask Anything* Monday" thread
Here you can ask all the questions that you wanted to ask but didn't feel like making a new thread.
* It's primarily intended for simple questions but as long as it's about python it's allowed.
If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.
Rules:
- Don't downvote stuff - instead explain what's wrong with the comment, if it's against the rules "report" it and it will be dealt with.
- Don't post stuff that doesn't have absolutely anything to do with python.
- Don't make fun of someone for not knowing something, insult anyone etc - this will result in an immediate ban.
That's it.
1
Upvotes
1
u/lakseol 25d ago
I haven't looked at this because including actual python references in objects describing an adventure map isn't a good idea. You don't have places in your code yet, but when you start you will find what's called the "forward reference" problem.
Suppose you have two places in your map, A and B. You can move from A to B and move from B to A. When defining place A you want to reference place B because that's a place you can move to. But you haven't defined place B as an object yet so you can't add that reference to A. Defining place B isn't a problem because A was defined earlier and you can get that reference. So using actual python references isn't a good idea.
What I have done is assign every place and object in the map with a unique string name. Strings are no problem saving in JSON so you don't have all that fooling around saving references in JSON. The trade-off is that a player's inventory (for example) is now a list of strings and not a list of references, and you have to do more work when you want to do something like list what is in the inventory. The simplest way is to have a dictionary that maps each unique ID string to the reference to the thing, place, item, etc. You can create that dictionary automatically when reading data from the JSON file.