0

[Python] How to make an object that stores objects?

I'm aware that ideally you'd make a game in C++ but I'd still like to try to make one in Python. However, I'm stuck when it comes to making inventories for players and enemies alike. Any help provided would be great, thank you in advance.

28th Oct 2019, 6:19 AM
Bela Olson
Bela Olson - avatar
12 odpowiedzi
+ 3
JSON - dictionary containing arrays of dictionaries. https://code.sololearn.com/cQQJW1163yWO/?ref=app
29th Oct 2019, 11:47 AM
Gordon
Gordon - avatar
+ 2
Since everything is object in Python, storing objects in one object's attributes would work. What framework or modules are you using for your game purposes?
28th Oct 2019, 7:20 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 2
Okay then how are you planning to create your game? Are you just planning for a command line one?
28th Oct 2019, 7:25 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 2
If you've an android device, try searching for Pydroid3 on play store and you're good to go
28th Oct 2019, 7:39 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 2
I appreciate the help, thanks
28th Oct 2019, 7:52 AM
Bela Olson
Bela Olson - avatar
+ 2
An object that stores objects, very simply you can use a list or a dictionary in Python for this. With a dictionary you could keep the count or the state of the object in the dict value. The dict value can also be a tuple or another list. Alternatively you can also create your own custom objects with OOP, or you can customize the standard list / dict by inheriting your own class from them.
29th Oct 2019, 6:06 PM
Tibor Santa
Tibor Santa - avatar
+ 1
What do you mean by framework? Also, I'm not using any modules besides random because I can't figure out how to make modules and import them
28th Oct 2019, 7:24 AM
Bela Olson
Bela Olson - avatar
+ 1
Essentially yeah. It's not the best way to do it, I know.
28th Oct 2019, 7:26 AM
Bela Olson
Bela Olson - avatar
+ 1
Got it. I thought it'd be a graphics based game so I asked about the modules.
28th Oct 2019, 7:28 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 1
Ah I wish, my computer's out of service right now so I can't really add graphics besides like ASCII
28th Oct 2019, 7:29 AM
Bela Olson
Bela Olson - avatar
+ 1
Not a problem. Btw, you could do it right from your phone now 📱😅
28th Oct 2019, 7:31 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 1
Nani?!? How so?
28th Oct 2019, 7:35 AM
Bela Olson
Bela Olson - avatar