Question

I'm having some trouble handling basic skill increases. Right now the code looks like

huntluck = 11
huntskill = 1

def hunt(self):
    global result, huntluck, huntskill

    hunting = random.randint(0, huntluck)

    if hunting == 0:
        result = "You couldn't find anything."
    elif hunting >=10:
        huntluck += 1
        huntskill += 1
        result = ("You succeeded in hunting. Your hunting skill increases. " +
        "(%s)" %huntskill)

Luck and skill are separate because I wanted the chance for hunt lvl 1 to succeed to be one in ten, but I also wanted to display the skill properly. It's a pretty hamhanded approach, but that's only part of the trouble.

Everything prints right, but when the user succeeds, there's like about a 50/50 chance the skill level won't go up.

You succeeded in hunting. Your hunting skill increases. (2)

You succeeded in hunting. Your hunting skill increases. (2)

You succeeded in hunting. Your hunting skill increases. (3)

You succeeded in hunting. Your hunting skill increases. (3)

You succeeded in hunting. Your hunting skill increases. (3)

You succeeded in hunting. Your hunting skill increases. (4)

I intend for the skill level to raise every time the player succeeds at hunting. Obviously that's not happening...

Can you see what I'm doing wrong? How can I fix it? How can I do things better?

Thank you!

Was it helpful?

Solution

You only set a new value for result if hunting is equal to 0 or larger than 9. If hunting is equal to 1-9, then result remains the old value, and you reprint that.

Change your hunting test:

if hunting < 10:
    result = "You couldn't find anything."
else:
    huntluck += 1
    huntskill += 1
    result = ("You succeeded in hunting. Your hunting skill increases. " +
    "(%s)" %huntskill)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top