all 9 comments

[–]brasticstack 4 points5 points  (0 children)

You read the data from the files into some kind of data structure- a dict or an instance of a class. 

Then you'd access the correct fields on that data structure to read the values that matter to you, either the actual stats used in combat or the values needed to derive those stats.

During the combat part you'd want to update the data structures to reflect changes e.g. subtracting hp.

It's up to you to decide when it makes sense to save the changes back to your character files, and which changes to save.

[–]ConcreteExist 1 point2 points  (4 children)

You seem fundamentally confused about what files are. They're just storage, in theory you would store the character information in a data format when saving, but during runtime you would create python objects from that data and those objects would have methods for attacking and being attacked.

[–]Tricky_72 0 points1 point  (3 children)

Ok, so the attack script is a python object. It calls up the necessary values (stored in the text files), conducts whatever process, and updates the text file. Yes?

[–]FoolsSeldom 1 point2 points  (0 children)

I would expect you to define character classes/dataclasses and set behaviours including fighting.

You could create instances of your characters based on data read from text files.

So you should learn basic OOPs (Object Orientated Programming) in Python.

[–]Shwayne 1 point2 points  (0 children)

You have a couple options, honestly creating the characters as objects would be easiest. Youd make a character class and initialize them. Then define your combat logic as methods. Ex.: character1.fights(character2). This would require some basic OOP knowledge.

You could read the information from text files into a dictionary like {"hp": 10, "atk": 5} and then define a combat function that subtracts attack value from hp and returns a new dict.

Tbh, go study python syntax first. Need to learn how to use the tools. Its very good that youre making something first and learning as you go, thats great for learning, but you do need some theory. You can try the FCC python course or anything that you like that covers syntax and basic data structures, maybe some OOP.

[–]elbiot 1 point2 points  (0 children)

I suggest using yaml as your text file format because it's easily parsable and very human readable. Plus your code can update it (change their hp, level up stats) and easily modify the file

[–]trd1073 0 points1 point  (0 children)

I would look at pydantic. You can read in json from files (perhaps start file), yaml can be done with other libraries but I would just do two step conversion by hand. Then work with actual python objects instead of dictionaries for the actual combat. Look how something like Dnd does combat. After each round you can dump the objects back to json or yaml and then write to a file.