Yesterday, with the help of this discord, I produced this tool that generates an rpg character with some extra features.
I am hoping some will look at it and tell me general thoughts about how to make the code better / more efficient, etc., or .. you know .. break it!
Looking for ground-up philosophy stuff. Organization, etc.
Thank everyone for all the help!
https://paste.pythondiscord.com/MAWA
#π RPG Character Builder - looking for insight
436 messages Β· Page 1 of 1 (latest)
@mild fox
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
Hello again.
One thing I see is at the end, you have basically the same loop several times. Twice for parental races, and then again for the job. I would probably try to make that a function that I call three times to neaten it up.
I may also move the randomization out of the class. By rolling inside the class initializer, you're making it harder to test, since a test can't just supply its own value for, for example, strength.
for ur str dunder method it might be cleaner to use a f triple string
def __str__(self):
return f"""
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here you are {self.player_name},
an assigned {self.player_sex} child
born to a {self.mother_race} mother
and a {self.father_race} father.
(etc)
"""
so all races and jobs would go to one list ?
does that prevent me from having to f every line?
No, the list to check against would become a parameter of the function, and would be passed in. The first two calls would be passed the race list, the last would be passed the job list.
ye
it's "faster", well easier to code and looks cleaner
a triple string covers multiple lines and is enclosed by 3 quotation marks or speech marks, so u dont have to print out each line seperately, and u only need 1 f at the beginning of the string block
do you need quotes on each line?
nope
just the beginning 3 quotes, and at the end
print("""
Hello
World!
12345
""")
is the same as
print("\n"
"Hello\n"
" World!\n"
"12345\n"
)
#or
print("\n")
print("Hello")
print(" World!")
print("12345")
def __str__(self):
return f"""
\n
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\n
Here you are {self.player_name},
an assigned {self.player_sex} child
born to a {self.mother_race} mother
and a {self.father_race} father.
\n
You take after your {dominant_parent}'s
{self.effective_race} side as you have {trait_1} & are {trait_2}.
\n
{rec_trait}
\n
You're employed as a {self.player_job} of low reknown.
\n
You have the following statistics:
\n |
STR: {self.strength} | DEX: {self.dexterity} |
CON: {self.constitution} | INT: {self.intelligence} |
WIS: {self.wisdom} | CHA: {self.charisma} |
\n
You have the following wealth:
\n |
PP: {self.platinum_pieces} | GP: {self.gold_pieces} |
EP: {self.electrum_pieces} | SP: {self.silver_pieces} |
CP: {self.copper_pieces} |
\n
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\n
"""
something broke the whole tool
whats the error
just quits no error
uh
can you print something else after the job selection if statement
see if any of the code after it is running
That looks like you made the function change I suggested and broke something.
What's the new code?
i didnt actually do that
it was just the triple string thing?
yes
ohh
lol ur not printing player_name at the end
mustve accidentally deleted at some point
shit
oh god
well it works but
Here you are Testerooni,
an assigned female child
born to a elvan mother
and a human father.
You take after your mother's
elvan side as you have pointed ears & are swift of thought & action.
From your father, you gain some of a human's an unremarkable appearance & are quite talented.
You're employed as a Clerk of low reknown.
You have the following statistics:
|
STR: 7 | DEX: 8 |
CON: 10 | INT: 9 |
WIS: 3 | CHA: 7 |
You have the following wealth:
|
PP: 10 | GP: 68 |
EP: 68 | SP: 525 |
CP: 5064 |
lol
ok so a new line in the """ already means a new line?
ye
ok i have settled everything after the f style changes, and i have condensed the colums back to <80
in terms of breaking the 3 sections out into a function .. i'm not sure how to go about that .. can you give me more ?
A general "recipe" for making repeated code into a function is to make the common parts the body of the function, and make the parts that differ parameters of the function.
sorry .. i don't understand the structure of the function in your head .. i'm barely hanging on here
the function doesn't have a list, but instead the list items are passed as parameters?
i have tyhe traits thing dependent on the indexing of the races list
not sure if that matters
i think he means
if u take a gander at the code
these parts are pretty much the same
so is the red
so instead of repeating those while blocks over and over again
make a function with the same "skeleton" u can use repeatedly
and pass in the values, for example the list of jobs or list of races, into that function
i think its called "modular programming"
oh right
uh
for the 2 blue ones at the top
def get_option(options):
while True:
print(options)
#could pass in a name parameter for the type of option ur picking, and put that here
option_input = input("Choose a valid option: ")
if option_input.casefold() in options:
return option_input.lower()
else
print("Please enter a valid option")
races = [ 'dwarvan', 'elvan', 'gnoman', 'goblan',
'halvan', 'human', 'northman', 'orcan'
]
mother_race = get_option(races)
father_race = get_option(races)
might need to adjust it for the jobs, but the main idea is finding the code in common with each repeated section
and using more common variables to simplify them
Yes, this is pretty much exactly what I meant.
π
thanks .. what does the commented text mean?
I think they meant to pass in a string so it doesn't say "option":
def get_option(options, label):
while True:
print(options)
option_input = input(f"Choose a valid {label}: ")
. . .
mother_race = get_option(races, 'race')
Note the second parameter/argument.
yep that
ah yes i was just thinking about that
it could also be used to differentiate between the type of value u want to return, since i noticed the jobs are capitalized
so when returning the value have something like
def get_option(options, label):
while True:
...
if option_input.casefold() in options:
if label == "race":
return option_input.lower()
elif label == "job":
return option_input.capitalize()
else:
return option_input
else
print("Please enter a valid option")
ye
ty
np
def get_option(options, label):
while True:
print(options)
#could pass in a name parameter for the type of option ur picking, and put that here
if label == "mrace":
option_input = input("Choose a race for your mother: ")
if label == "frace":
option_input = input("Choose a racefor your father: ")
elif label == "job":
option_input = input("Choose a job: ")
if option_input.casefold() in options:
if label == "race":
return option_input.lower()
elif label == "job":
return option_input.capitalize()
else:
return option_input
else:
if label == "mrace":
print("Please enter a valid race for your mother. ")
elif label == "frace":
print("Please enter a valid race for your father. ")
elif label == "job":
print("Please enter a valid job. ")
races = [ 'dwarvan', 'elvan', 'gnoman', 'goblan',
'halvan', 'human', 'northman', 'orcan'
]
jobs = [ 'angler', 'baker', 'bailiff', 'carpenter', 'clerk',
'cobbler', 'farmer', 'hunter', 'mason', 'miller',
'porter', 'tailor', 'weaver', 'woodcutter'
]
mother_race = get_option(races, "mrace")
father_race = get_option(races, "frace")
player_job = get_option(jobs, "job")
looks fine, i dont think u can really get past the "mother vs father" thing
slight change just visibly is using whitespaces to split ur code so its more readable
eh?
def get_option(options, label):
while True:
print(options)
if label == "mrace":
option_input = input("Choose a race for your mother: ")
elif label == "frace":
option_input = input("Choose a racefor your father: ")
elif label == "job":
option_input = input("Choose a job: ")
if option_input.casefold() in options:
if label == "race":
return option_input.lower()
elif label == "job":
return option_input.capitalize()
else:
return option_input
else:
if label == "mrace":
print("Please enter a valid race for your mother. ")
elif label == "frace":
print("Please enter a valid race for your father. ")
elif label == "job":
print("Please enter a valid job. ")
races = [ 'dwarvan', 'elvan', 'gnoman', 'goblan',
'halvan', 'human', 'northman', 'orcan'
]
jobs = [ 'angler', 'baker', 'bailiff', 'carpenter', 'clerk',
'cobbler', 'farmer', 'hunter', 'mason', 'miller',
'porter', 'tailor', 'weaver', 'woodcutter'
]
mother_race = get_option(races, "mrace")
father_race = get_option(races, "frace")
player_job = get_option(jobs, "job")
all of this works well, but i think the if list is ugly af and im pretty sure its structured badly, if not incorrectly for the application
its a very small thing but just adding extra lines of space so its not clumped together
idk
do yk what they are
no
you know nearly everything i know
nearly everything i know about coding is in this tool right now lol
oh lol im assuming ur new to python then?
i have ahold of some other concepts in a vague sense, but really all i have ever done is some work out of the "learn python by solving problems" nostarch book and this
oh thats fair enuf fine ye
i have done some basic learning in delphi/pascal and c++, and i have an ancient background in actual html
oh thats way more than me then
ive pretty much tried to only master python
cuz im too stupid for anything else
LOL
im 45yo
i had an opportunity at a job to try and change a value in a report that queries databases, so that they can have me do it instead of gainfully employing an actual coder
and, unlike other times in my life where i have considered shifting careers, i'm actually running with the ball this time
well that sounds exciting
me doing python is like a week old
oh ur doing entirely fine so far then, ive seen way more experienced people sending ABHORRENT code here
i have to learn SQL to do the thing at my job, but at least i can understand and recognize the path to do what they need
i did a stint as a building-code inspector, so i have some kind of professional detail orientedness which is helping me vastly compared to when i tried to learn web dev decades ago
no i was a "special inspector" which is basically making sure contractors do the work they said they would do to certain specifications
i had to learn my sections of the international building code as well as local codes, how to read plans and specifications (where a little symbol might mean a paragraph of detail), and how to cross all my i's and dot all my t's (lol), not that i bring those skills into normal typing with me lol
i'm trying to get better at home row while i do this coding, too. lol.
sounds silly but i reckon just type a lot, not just coding
even while in calls for example over discord, i tend to only type
and naturally i've learnt touch typing via that
NO is not matching n or no .casefold for some reason after i did a line to lowercase the return
def fate_sex():
yes_answers = ['y', 'yes']
no_answers = ['n', 'no']
answers = yes_answers + no_answers
while True:
sex_test = input('Will you allow FATE to decide your sex? ')
if sex_test in answers:
if sex_test.casefold() in yes_answers:
fate = random.randint(0, 100)
if fate < 49:
player_sex = 'male'
player_sex = player_sex.lower()
return player_sex
elif fate > 51:
player_sex = 'female'
player_sex = player_sex.lower()
return player_sex
else:
player_sex = 'intersex'
player_sex = player_sex.lower()
return player_sex
elif sex_test.casefold() in no_answers:
sexes = ['female', 'intersex', 'male']
while True:
print('female', 'intersex', 'male')
player_sex = input('What is your sex then? ')
if player_sex.casefold() in sexes:
player_sex = player_sex.lower() #added line
return player_sex
else:
print('Please enter a valid sex.')
else:
print('All that is required from you is a yes or a no.')
honestly im not entirely sure wut casefold() does ive only stuck to .lower()
casefold takes AnY iNpUt that is checked against a list for ('any input')
does that make sense?
idk the programmer way to say it
at least thats what i think
!d str.casefold
str.casefold()```
Return a casefolded copy of the string. Casefolded strings may be used for caseless matching.
Casefolding is similar to lowercasing but more aggressive because it is intended to remove all case distinctions in a string. For example, the German lowercase letter `'Γ'` is equivalent to `"ss"`. Since it is already lowercase, [`lower()`](https://docs.python.org/3/library/stdtypes.html#str.lower) would do nothing to `'Γ'`; [`casefold()`](https://docs.python.org/3/library/stdtypes.html#str.casefold) converts it to `"ss"`.
The casefolding algorithm is [described in section 3.13 βDefault Case Foldingβ of the Unicode Standard](https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf).
Added in version 3.3.
casefold works for unicode
ah and lower only for alpha then?
lower for display, casefold for comparison
got it thx
no worries
and i think i am using casefold, capitalize, and lower correctly .. but for some reason "will you allow FATE...." is not accepting "NO"
oh
its borked fr now
it wont accept No Yes or YES either
oh i got it
if sex_test in answers: this line
its missing a case_fold asw
so none of the nested if statements trigger
got it
cool
oh neat
so i just made the input =.lower
and got rid of all the casefold and extra lowers
def fate_sex():
yes_answers = ['y', 'yes']
no_answers = ['n', 'no']
answers = yes_answers + no_answers
while True:
sex_test = input('Will you allow FATE to decide your sex? ')
sex_test = sex_test.lower()
if sex_test in answers:
if sex_test in yes_answers:
fate = random.randint(0, 100)
if fate < 49:
player_sex = 'male'
player_sex = player_sex
return player_sex
elif fate > 51:
player_sex = 'female'
player_sex = player_sex
return player_sex
else:
player_sex = 'intersex'
player_sex = player_sex
return player_sex
elif sex_test in no_answers:
sexes = ['female', 'intersex', 'male']
while True:
print('female', 'intersex', 'male')
player_sex = input('What is your sex then? ')
player_sex = player_sex.lower()
if player_sex in sexes:
return player_sex
else:
print('Please enter a valid sex.')
else:
print('All that is required from you is a yes or a no.')
oh thats much smarter lol
yeah i have been fearing this:
From your mother, you gain some of a dwarvans a beard.
a / an
and other grammar
is that all done with if statements normally?
I'm trying to break the stat rolling out of the class as suggested.. this is as far as i've gotten in my head
@vestal narwhal @tall totem @tall bloom sorry to tag you guys but i dont want to make a new post if i dont have to.
def rollstats(stat):
for i in stat:
stat = roll(3, 4)
return stat
rollstats(strength, dexterity, constitution, intelligence, wisdom, charisma)
basically that they are the forms with which to create objects
i'm 3 chapters in to the "learn python by solving problems" book so far, tho i have more nostarch on the way as well ... that and various youtube tutorials
i know that its possible to make classes for all the races and all the jobs, and then make a character class that picks and chooses attributes from other classes, but i'm super duper not there yet
yesterday and today are the first times i have sought person-help
I'm not familiar with that book. What does it tell you about functions and function arguments in Python?
im trying not to get caught in the "i have done a thousand tutorials, but cannot write any code" trap i hear a lot about BY getting into this and envisioning something first and then creating it (or asking for help creating it)
functions are a type of method that returns a value
in pascal, they have functions and procedures .. the difference is that procedures do a thing without returning a value
i dont really know how to differentiate them in python
i know they are both types of methods
i know that arguments are a form of parameter
i dont think its worth differentiating them into procedures in python cuz ultimately
they're always defined using the "def" parameter
its just that by technicality
i dont REALLY understand how to "pass" things "into" a function .. trying to piece that together
a function would have the "return" statement in it
a procedure wouldnt
but they're defined the same
thats what i kinda guessed
So maybe you should start there and hold off on your RPG builder for a minute.
i know i'm over my head
My fear is that you're going to try to do too many things at once and overwhelm yourself then burnout.
a large problem i have is that it can be explained a zillion times and i wont understand until i do it
thank you for being concerned. i am 45 years old, taking this pretty seriously, and i'm not likely to burn out. :)
So you mentioned Pascal and SQL before. Do you know either of those languages?
i very much know i'm treading water over the deep, and i absolutely plan to hit the books again soon, but im just trying to use this project to connect abstract concepts with "a thing i have done"
i started this L2 program kick at my current job .. they use reportbuilder to query databases, and have to pay a legitimate pascal guy to do it every time they want a little change. they asked me if i could look at it. that was a month ago. i've learned some of the basics of pascal, c++, and python since.
I have LOOKED at SQL, but have not started learning it yet at all.
i say pascal, i mean delphi
not really sure what i should say, but i mean i used the delphi ide to help me learn and write sme pascal
i know more python than anything else at this point
and like i told sh, you know pretty much everything i know .. there is very little that i know that is not contained in this project
https://docs.python.org/3/tutorial/controlflow.html#defining-functions <- I think this will help you with your current conundrum.
i have a hard time with stuff like that because it starts off deep in the weeds
yeah i don't know what the important things are in that page that you want me to learn
what online tutorials have you used
def rollstats(stat):
for i in stat:
stat = roll(3, 4)
return stat
stat = rollstats(strength, dexterity, constitution, intelligence, wisdom, charisma)
oh idk man random stuff .. haven't found a great series yet
may i present to you, clear code
The complete introduction to Python. This video will cover every part of it and also include lots of exercises so you can practice.
If you want to support me: https://www.patreon.com/clearcode
(You also get lots of perks)
Link to the full course:
https://www.udemy.com/course/learn-python-by-making-games/
Social stuff:
Twitter - https://twi...
cool
i think it's considered one of the better ones
ok the problem here is
also its in the class which idk if it should be:
class player_character:
def __init__ ( self, player_name, player_sex,
mother_race, father_race, player_job,
strength, dexterity, constitution,
intelligence, wisdom, charisma
) :
self.player_name = player_name
self.player_sex = player_sex
self.mother_race = mother_race
self.father_race = father_race
self.player_job = player_job
self.effective_race = effective_race
self.dominant_parent = dominant_parent
self.recessive_race = recessive_race
self.recessive_parent = recessive_parent
self.trait_1 = trait_1
self.trait_2 = trait_2
self.recessive_trait_1 = recessive_trait_1
self.recessive_trait_2 = recessive_trait_2
self.rec_trait = rec_trait
self.strength = strength
self.dexterity = dexterity
self.constitution = constitution
self.intelligence = intelligence
self.wisdom = wisdom
self.charisma = charisma
self.platinum_pieces = roll(3, 4)
self.gold_pieces = roll(8, 12)
self.electrum_pieces = roll(16, 12)
self.silver_pieces = roll(80, 12)
self.copper_pieces = roll(800, 12)
i think it doesnt need to be in the init because the values are not input but rather generated, right?
init is used to make an instance of a class,
its mostly used for when u nee to make many instances quickly
for example lets say u were making a multiplayer game, rather than writing player_character1, player_charater2 etc and all their details
u just do
p1 = player_character(their details)
p2 = player_character(different details)
and each of their details are contained within their own instance
since theres only 1 instance in ur game though
it won't really matter
oh right
idk if that actually changes what you said since its one at a time
but eventually, i want a file that has ten outputs
no it definitely does, because then the roll()'s do need to be inside the init
if u had it outside
lets say at the top of the code
all the characters u make would have the same stats
keeping it inside the init, rerolls each stat everytime u make a new character, or initialise one
this is basically an NPC generator (thats why low d&d stats) .. players create 10 sorta normies, and then play all of them through a "funnel" adventure in which i kill nearly all of them .. the ones that survive the cataclysmic events end up being the play characters, and in the events, they discover new things about themselves (the extra 6 possible stat points) based on their actions
and THEN they choose a proper class
and become level 1
idk if that makes sense to you or not, but its the context of the tool
and then after that i can use the tool to quickly generate NPCs as well
yes
but like .. i know i could output the results 1 at a time to another file if that was less efficient
i just have no idea how
im not REALLY trying to do that rn
im trying to get the basics of the tool working and also optimized just as a learning event (this)
i will likely rewrite and iterate this several times, but this is absolutely as deep as i have been thusfar
good to hear that's the only way to improve
so the init args are for things that are directly input by the user tho, right?
thats what i was asking about
so the stats dont need to be in the init parentheticals?
or am i missing something
im just confused because do u want strength, dexterity, constitution etc. to be inputted by the user
oh ok
then yes
but after i did that i kinda realized why it wasnt the thing to do
ok
when i took those out of the ()'s, these yellowed out and are underlined
i need those to set strength (class) from self.strength (object) right?
or other way around?
wait strength is a class?
ok quick naming thing
class Thing:
def __init__(self, para):
self.attr = para
def jump(self):
...
obj = Thing()
Thing is the class
self.attr is an attribute to the class, "Thing"
para in line 2 is a parameter to the init() function u use to assign values to ur object's attributes in line 3
jump() is a method of Thing objects
and obj is an object of instance of the class Thing
ok
now then
do u want strength, dex etc to be rolled everytime
u make a new npc
yes
ok u can just put
self.strength = roll(a, b)
self.dexterity = roll(a, b)
...
where a and b are ur different values or range
thats what i had
oh what was the problem with it
and the other dude said it would be cleaner to break that functionality out of the class
and then call to it
ah i see he wanted u to pass it through the parameters
like the user inputted ones u were talking about
in case u wanted to test specific stats
i dont understand :/
ok so
class Player1:
def __init__(self, name):
self.name = name
self.strength = roll(2, 5)
class Player2:
def __init__(self, name, strength):
self.name = name
self.strength = strength
btw, in case u have to go suddenly .. THANK YOU for taking the time to teach me.
lets say i create an instance of Player1
so
p1 = Player1("bob")
print(p1.strength)
if u ran that code multiple times
the strength value would change every single time
because python doesn't remember what happened the last time u pressed the run button
right
it's reintialised in the init method
oh
so if i were to do some command line "what is bobs strength" it would be like "wtf is bobs strength" ?
i mean more that
everytime u ask what is bobs strength
it gives u a different number everytime
ye hopefully lol
anyway thats different to if u made an instance of Player2
basically it destroys the data after returning it
p2 = Player2("bob", 5)
print(p2.strength)
yes exactly
this would always say bob has 5 strength
since everytime u intialise his instance
u always put in 5 strength
ok so that seems to cover the second part of his reason
oh nevermind
i misunderstood
ok so you LIKE the way it was .. the way that coins are, now? without the idea of "keeping track of bob"
and if not for bob, you would have left it that way?
sorry ill repaste
^ is broken right now
i personally prefer how the coins are now
i see why its better to "keep track of bob" but personally i wouldn't do it especailly with this many parameters
like for instance .. before, i had each stat rolling its own "random.randint(1, 4)" inside the class, so i assumed that the other guy was saying that i could move the statrolling function out, and call to it more efficiently like that was, too.
someone suggested yesterday to make the function at the top that rolls the settable dice, and i really liked that
instead of each stat rolling 3 times inside the class
ye thats a good addition
unbroken: https://paste.pythondiscord.com/JOAQ
not sure why self. is required in the code sometimes and not others
its a class specific thing
self technically could be any other word, its just convention
def __str__(self):
return f"""
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here you are {self.player_name}, \
an assigned {self.player_sex} child \
born to a {self.mother_race} mother \
and a {self.father_race} father.
You take after your {effective_race} {dominant_parent}, \
as you have {trait_1} & are {trait_2}.
{rec_trait}
You're employed as a {self.player_job} of low reknown.
You have the following statistics:
| \
STR: {self.strength} | DEX: {self.dexterity} | \
CON: {self.constitution} | INT: {self.intelligence} | \
WIS: {self.wisdom} | CHA: {self.charisma} |
You have the following wealth:
| \
PP: {self.platinum_pieces} | GP: {self.gold_pieces} | \
EP: {self.electrum_pieces} | SP: {self.silver_pieces} | \
CP: {self.copper_pieces} |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
i would recommend looking in the clear code tutorial
ok
it took me a while to grasp classes fully but you've done pretty well for diving straight in to the deep end
the tutorial should just help with the understanding a bit more, it's hard to explain just by typing
i get it
its harder to teach than to learn sometimes because you have to walk back your understanding, in addition to having your understanding
as hard as it is to ask the right questions, lol...
ye, plus people just learn differently
i personally need diagrams and random annotations for me to get the gist of it
i just took out 3 lines from the class that don't seem necessary and i think i was right .. i think i added these just guessing .. what else is not needed?
https://paste.pythondiscord.com/LGYA
i say they dont because they work in the clip ^^above
without the self.
thats most likely because ur only working with 1 character right now
not entirely certain yet, but when u make ur 10 characters they might end up sharing the same traits
oof
can't i output every print to another file?
or to a comment?
or something?
an array?
as in
like
do u want to store them somewhere
im thinking yeah
name sex mrace frace erace rrace trait3 trait4 job str dex con int wis cha pp gp ep sp cp
trait1 and trait2 are implied by erace
so thats pretty much every value lol
do u just want the values
thats the way a coder would do it right?
no just the values
that way i can replicate the text if i wanted to, but im just storing the values for each player
alr uh
it would probably be better to rewrite the whole thing with that in mind huh lololol
would it be super easy just to store the text since its already set up to print it to the terminal?
class player_character:
... #ur __init__ and __str__ methods
def save(self):
file = open("filename.txt", "w")
file.write(f"{self.name};{self.sex};{self.strebgth};{self.dexterity};etc")
file.close()
oh thats easier
class player_character:
... #ur __init__ and __str__ methods
def save(self):
file = open("filename.txt", "w")
file.write(self.__str__())
file.close()
ah
would that append an existing file?
def save(self):
file = open(f"c:\{player_name}.txt", "w")
file.write(self.__str__())
file.close()
ah no
"w" stands for write, which clears the entire file
and then writes to it
if u want to append u should replace teh "w" with "a"
also
add a "\n" to the file.write
file.write(self.__str__() + "\n")
def save(self):
file = open(f"{player_name}.txt", "a")
file.write(self.__str__()) + "\n"
file.close()
no no
the "\n" needs to be inside of the write() brackets
wut ur doing is attaching a newline to the printed text, and putting ALL of it in the file
def save(self):
file = open(f"{player_name}.txt", "a")
file.write(self.__str__() + "\n")
file.close()
its not making a file .. is it really being "run" inside vs code or do i need to make an actual executable?\
ok i ran it through actual python, still nothing .. tried adding a path, and it sees \ as an escape, .. im thinking it needs a linux path or something?
idk
i've run the .py program in python, and via vs code, and no file is being created. i have never done this. sorry to poke you again, but im v close to understanding .. online searches are just showing me what you showed me
OMFG I GOT IT
oh lol
and then i tried and tried
finally i gotr it with: player_character.save(player_name)
nice
yeah .. just running it a few times, i'm pretty happy with the results at this point
https://paste.pythondiscord.com/3ZEQ is a set of 36 test characters showing the distribution of traits for a elvan/human combination with the dominant/recessive logic, in case you were interested. also, 36 fate+ tests until an intersex person appeared.. a bit over reality, but pretty good imo
oh cool is that every combination
not sure tbh
every race has 2 traits
dominant race gets both
recessive race has a 1 in 3 chance to get either
so i think a 1 in 9 to get both
and the dominant parent is 50/50 so for each 2 race coupling, there are 8? trait combos possible
so you could be mostly elvan, but your orcish mother left you with tusks
or you could be mostly elven but your orcish mother left you with an intimidating presence
or both
or neither
im struggling to get the text file to have a dynamic name
i have entered new code to accept a player name as well as a character name
i would like to name the file after the player
i have tried f"{player_name}.txt" and player_name + ".txt" and variations, nothing is working .. anything i do get to work creates a file called None.txt (thx python)
with open("myBigFile.txt") as f:
subfiles = {}
for line in f:
claim = line.split("*")
if not str(claim[1]) in subfiles:
subfiles[str(claim[1])] = open("DATE-" + str(claim[1]) + ".txt", "a")
subfile[str(claim[1])].write(claim[0]+"*"+claim[2]+"\n")
im beginning to think you cant do it from inside the class
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.