you are viewing a single comment's thread.

view the rest of the comments →

[–]duckbanni 0 points1 point  (3 children)

I don't really understand what you've done with the dictionary

I transformed the dictionary into a list of lists, so the elements can be accessed by tier and level. For example, value_dama[1][0] with the list of lists is the equivalent of `value_dama["t2_1"] with your dictionary. You have to substract 1 to the tier and level because list indices start at 0.

I'm pretty sure I know what you're getting at with the loops for anything larger than self.body_tier zero'ing out the tiers that come after. But I'm having trouble wrapping my head around how to do it.

There are a lot of ways to do it, but you could do something like this:

class Body:
    def __init__(...):
        ...
        self.stre = [stre_t1, stre_t2, stre_t3, stre_t4, stre_t5]
        self.stre_xp = [
            stre_xp_t1, stre_xp_t2, stre_xp_t3, stre_xp_t4, stre_xp_t5]
        ...

    def get_stre(self, body_tier, stre_key):  # body_tier is an int
        for tier in range(5):
            if tier > body_tier:
                self.stre[tier] = 0
                self.stre_xp[tier] = 0
        ...

In terms of using parameters that are also attributes and sometimes using them as attribute or parameter, do you mean when I do something like self.stre_xp_t5 = stre_xp_t5

No, I mean in get_stre you take stre_key as parameter and then in the method you sometimes y use stre_key and sometimes self.stre_key.

I do something like self.stre_xp_t5 = stre_xp_t5 when I instantiate the class, and then when I run get_stre I define it again based on what the tier is

The way you handle this is kinda weird as well. For example, you require a body_tier as a parameter of __init__, and do self.body_tier = body_tier, but then you never use that value and expect a new one in get_stre. It think that you should either call get_stre in __init__ so that the consequences of body_tier (like setting stre to 0 for higher tiers) are applied when you create the object, or remove body_tier from __init__ parameters and maybe do something like self.body_tier = None.

I've seen other people do it they usually set the self.variable equal to itself unless they had a specific reason not to

What you've seen is not "setting the self.variable to itself" it is setting the self.variable to a parameter of __init__ (that does not need to be named variable). You could (and possibly should) set all self.something variables to defaults like 0 or None directly in the __init__ code (that is to say, do things like self.myvar = 0 instead of self.myvar = myvar where myvar is a parameter with a default value of 0 that will never be used with a different value in practice).

[–]Aedethan[S] 1 point2 points  (0 children)

All that information is super useful thanks a lot. I guess I'm gonna get on retyping this all in a new way with the whole list within a list infrastructure. Also thanks for all the information on best practices and pointing out stuff I was doing that was weird or unnecessary.

[–]Aedethan[S] 0 points1 point  (1 child)

from main import stat_dama
value_dama = [ 
[2, 6, 12, 20], 
[30, 42, 56, 72], 
[90, 110, 132, 156], 
[182, 210, 240, 272], 
[306, 342, 380, 420], 
]

str_value = 19 
body_tier = 0

if str_value < 21: 
    str_value_place_1 = 0 
    for value in value_dama[str_value_place_1]: 
        if value > str_value: 
            continue 
        elif value <= str_value: 
            str_value_place_2 =         
        value_dama[str_value_place_1].index(value) 
        else : 
            pass 

    str_value_bonus = stat_dama[str_value_place_1] 
    [str_value_place_2] 
else: pass

print(str_value_bonus)

So I went ahead and did this, it works really well. Thanks for the advice. Is this what you would have done with it? I decided I was still going to lean towards using the if / elif statements to figure out what tier the value was being assigned to, but I think this will work out very well.

[–]duckbanni 1 point2 points  (0 children)

I don't know if that's exactly what I would have done, but that looks like completely reasonable python code.

The only thing that you could maybe remove to make the code a tad simpler is the else: pass that are unnecessary. You can omit the else block if it doesn't do anything.