#πŸ”’ RPG Character Builder - looking for insight

436 messages Β· Page 1 of 1 (latest)

mild fox
#

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

torn cometBOT
#

@mild fox

Python help channel opened

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.

tall bloom
#

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.

vestal narwhal
#

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)
"""

mild fox
mild fox
tall bloom
vestal narwhal
#

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

mild fox
#

do you need quotes on each line?

vestal narwhal
#

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")
mild fox
#
   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

vestal narwhal
#

whats the error

mild fox
#

just quits no error

vestal narwhal
#

uh

mild fox
vestal narwhal
#

can you print something else after the job selection if statement

#

see if any of the code after it is running

mild fox
#

it does

tall bloom
# mild fox

That looks like you made the function change I suggested and broke something.

#

What's the new code?

vestal narwhal
#

it was just the triple string thing?

mild fox
mild fox
vestal narwhal
#

ohh

#

lol ur not printing player_name at the end

#

mustve accidentally deleted at some point

mild fox
#

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?

vestal narwhal
#

ye

mild fox
#

ok i have settled everything after the f style changes, and i have condensed the colums back to <80

mild fox
tall bloom
mild fox
#

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

vestal narwhal
#

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"

mild fox
#

yes but i dont understand how to do it

#

i understand why to do it

vestal narwhal
#

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

tall bloom
vestal narwhal
#

πŸ‘

mild fox
tall bloom
#

Note the second parameter/argument.

vestal narwhal
#

yep that

mild fox
#

ah yes i was just thinking about that

vestal narwhal
#

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")
mild fox
#

how do i pass the label?

#

mother_race = get_option(races, "race") ?

vestal narwhal
#

ye

mild fox
#

ty

vestal narwhal
#

np

mild fox
#
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")
vestal narwhal
#

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

mild fox
#

eh?

vestal narwhal
#
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")
mild fox
#

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

vestal narwhal
#

its a very small thing but just adding extra lines of space so its not clumped together

mild fox
#

ok\

#

so logically that if tree is fine?

#

it's just ugly?

vestal narwhal
#

ye not much u can do about that

#

maybe a match statement?

mild fox
#

idk

vestal narwhal
#

do yk what they are

mild fox
#

no

#

you know nearly everything i know

#

nearly everything i know about coding is in this tool right now lol

vestal narwhal
#

oh lol im assuming ur new to python then?

mild fox
#

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

vestal narwhal
#

oh thats fair enuf fine ye

mild fox
#

i have done some basic learning in delphi/pascal and c++, and i have an ancient background in actual html

vestal narwhal
#

oh thats way more than me then

#

ive pretty much tried to only master python

#

cuz im too stupid for anything else

mild fox
#

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

vestal narwhal
#

well that sounds exciting

mild fox
#

me doing python is like a week old

vestal narwhal
#

oh ur doing entirely fine so far then, ive seen way more experienced people sending ABHORRENT code here

mild fox
#

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

vestal narwhal
#

oh that's cool

#

did you have to identify security issues or something

mild fox
#

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.

vestal narwhal
#

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

mild fox
#

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.')
vestal narwhal
#

honestly im not entirely sure wut casefold() does ive only stuck to .lower()

mild fox
#

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

tall totem
#

!d str.casefold

torn cometBOT
#

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.
tall totem
#

casefold works for unicode

vestal narwhal
#

ah and lower only for alpha then?

tall totem
#

lower for display, casefold for comparison

vestal narwhal
#

got it thx

tall totem
#

no worries

mild fox
#

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

vestal narwhal
#

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

mild fox
#

got it

vestal narwhal
#

cool

mild fox
#

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.')
vestal narwhal
#

oh thats much smarter lol

mild fox
#

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?

mild fox
#

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)
tall totem
#

What have you read about classes?

#

Are you using any resources to learn Python?

mild fox
#

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

tall totem
#

I'm not familiar with that book. What does it tell you about functions and function arguments in Python?

mild fox
#

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

vestal narwhal
#

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

mild fox
#

i dont REALLY understand how to "pass" things "into" a function .. trying to piece that together

vestal narwhal
#

a function would have the "return" statement in it

#

a procedure wouldnt

#

but they're defined the same

mild fox
#

thats what i kinda guessed

tall totem
#

So maybe you should start there and hold off on your RPG builder for a minute.

mild fox
#

i know i'm over my head

tall totem
#

My fear is that you're going to try to do too many things at once and overwhelm yourself then burnout.

mild fox
#

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. :)

tall totem
#

So you mentioned Pascal and SQL before. Do you know either of those languages?

mild fox
#

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

tall totem
mild fox
#

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

vestal narwhal
#

what online tutorials have you used

mild fox
#
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

vestal narwhal
#

may i present to you, clear code

mild fox
#

cool

vestal narwhal
#

i think it's considered one of the better ones

vestal narwhal
mild fox
#

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?

vestal narwhal
#

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

vestal narwhal
#

it won't really matter

mild fox
#

well

#

ok so the scope of this generator is to create and export ten characters

vestal narwhal
#

oh right

mild fox
#

idk if that actually changes what you said since its one at a time

#

but eventually, i want a file that has ten outputs

vestal narwhal
#

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

mild fox
#

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

vestal narwhal
#

got it alr

#

does each NPC need to have their own stats asw

mild fox
#

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

vestal narwhal
#

good to hear that's the only way to improve

mild fox
#

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

vestal narwhal
mild fox
#

no

#

i was just trying things to get that code^ to work

vestal narwhal
#

oh ok

mild fox
#

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?

vestal narwhal
#

wait strength is a class?

mild fox
#

i just meant on the class side

#

i dont know how to say these words right

vestal narwhal
#

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

mild fox
#

ok

vestal narwhal
#

do u want strength, dex etc to be rolled everytime

#

u make a new npc

mild fox
#

yes

vestal narwhal
#

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

mild fox
#

thats what i had

vestal narwhal
#

oh what was the problem with it

mild fox
#

and the other dude said it would be cleaner to break that functionality out of the class

#

and then call to it

vestal narwhal
#

hm i dont see what he means by that

#

unless he means

mild fox
vestal narwhal
#

ah i see he wanted u to pass it through the parameters

#

like the user inputted ones u were talking about

mild fox
#

i did the first suggestion

#

and yours

vestal narwhal
#

in case u wanted to test specific stats

mild fox
#

i dont understand :/

vestal narwhal
#

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
mild fox
#

btw, in case u have to go suddenly .. THANK YOU for taking the time to teach me.

vestal narwhal
#

no worries, i have a bit more time left

#

ill try get this bit done

vestal narwhal
#

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

mild fox
#

right

vestal narwhal
#

it's reintialised in the init method

mild fox
#

oh

vestal narwhal
#

which is bad for testing

#

cuz u want to use the same base case

mild fox
#

so if i were to do some command line "what is bobs strength" it would be like "wtf is bobs strength" ?

vestal narwhal
#

i mean more that

#

everytime u ask what is bobs strength

#

it gives u a different number everytime

mild fox
#

i think we mean the same thing

#

like i said idk how to speak lol

vestal narwhal
#

ye hopefully lol

vestal narwhal
mild fox
#

basically it destroys the data after returning it

vestal narwhal
#

p2 = Player2("bob", 5)
print(p2.strength)

vestal narwhal
vestal narwhal
#

since everytime u intialise his instance

#

u always put in 5 strength

mild fox
#

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

vestal narwhal
#

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

mild fox
#

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

vestal narwhal
#

ye thats a good addition

mild fox
#

not sure why self. is required in the code sometimes and not others

vestal narwhal
#

its a class specific thing

#

self technically could be any other word, its just convention

mild fox
#
    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} |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
""" 
vestal narwhal
#

i would recommend looking in the clear code tutorial

mild fox
#

ok

vestal narwhal
#

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

mild fox
#

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...

vestal narwhal
#

ye, plus people just learn differently

#

i personally need diagrams and random annotations for me to get the gist of it

mild fox
#

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.

vestal narwhal
#

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

mild fox
#

can't i output every print to another file?

#

or to a comment?

#

or something?

#

an array?

vestal narwhal
#

as in

mild fox
#

like

vestal narwhal
#

do u want to store them somewhere

mild fox
#

im thinking yeah

vestal narwhal
#

uhh

#

ok well what are u printing

#

or at least

#

what do u need to store

mild fox
#

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

vestal narwhal
#

so thats pretty much every value lol

mild fox
#

3 and 4 are 'mays'

#

oh .. yes

#

all the values

#

lol

#

minus trait1 and trait2

vestal narwhal
#

do u just want the values

vestal narwhal
mild fox
#

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

vestal narwhal
#

alr uh

mild fox
#

it would probably be better to rewrite the whole thing with that in mind huh lololol

vestal narwhal
#

uhh

#

nah u can add another method

#

to ur player_character class

#

something like

mild fox
#

would it be super easy just to store the text since its already set up to print it to the terminal?

vestal narwhal
#
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()
mild fox
#

oh nice

#

that is awesome to make a new file

vestal narwhal
#
class player_character:
    ... #ur __init__ and __str__ methods

    def save(self):
        file = open("filename.txt", "w")
        file.write(self.__str__())
        file.close()
mild fox
#

ah

#

would that append an existing file?

#
def save(self):
        file = open(f"c:\{player_name}.txt", "w")
        file.write(self.__str__())
        file.close()
vestal narwhal
#

"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")

mild fox
#
def save(self):
        file = open(f"{player_name}.txt", "a")
        file.write(self.__str__()) + "\n"
        file.close()
vestal narwhal
#

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

mild fox
#
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

mild fox
vestal narwhal
#

uhh

#

prolly a directory issue

#

try slapping this at the top of ur code

mild fox
#

OMFG I GOT IT

vestal narwhal
#
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))```
#

oh ok

mild fox
#

i didnt make the call

#

at the end

vestal narwhal
#

oh lol

mild fox
#

and then i tried and tried

#

finally i gotr it with: player_character.save(player_name)

vestal narwhal
#

nice

mild fox
mild fox
# vestal narwhal nice

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

vestal narwhal
#

oh cool is that every combination

mild fox
#

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

torn cometBOT
#
Python help channel closed

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.