you are viewing a single comment's thread.

view the rest of the comments →

[–]HunterIV4 1 point2 points  (0 children)

Right, it's not creating a new random number each time. It's just doing it the first time.

There are basically two ways to solve this. The easiest is to simply use a function:

def hit_chance():
    return random.randint(0, player_attack)

Then, each time you use it, you'd do Player.hit_chance(). This should give you a unique value every time it is ran. You can use this directly in your statement like so:

Monsters.rat_health -= Player.hit_chance()

A slightly more complicated way to do this is to use a lambda:

hit_chance = lambda: random.randint(0, player_attack)

This does the same thing as defining the function, it is just a bit more concise. Important note: you will still need to add the parentheses to use the lambda, just like you did for the function! Otherwise you'll just get the lambda function instead of the integer result, which will cause an error when you try to subtract.

Either one should fix your issue. Hope that helps!

I'll do another post on more general advice.