0
\$\begingroup\$

Bit new to python. I'm making a game where you click on a strawberry, then it reappears in a new location, and so on and so forth. But you see, every time the player misclicks, they lose Score equal to their Crapscore. Their Score is increased by 10 each time they click on the strawb, and the Crapscore is increased by 10 for each time they miss the strawb. But you see, what the on-screen Crapscore says does not equate to exactly how much the player will lose. I want the Crapscore on screen to equal the exact amount of Score they will lose if they misclick. I've tried messing around with different variables, but I can't get it to work.

Crapscore begins at 10, then if the player misclicks, crapscore is increased by 10. Then, the Score is decreased by Crapscore. What shows on screen works, but it's not a code error. I just can't figure out how to make it so that the player's Score is decreased EXACTLY by the player's current Crapscore. Below is the main code with the crapscore and score.

def on_mouse_down(pos):
    global crapscore
    global score
    global hit
    global crapscoreonscreen
    if strawberry.collidepoint(pos):
        score = score + 10
        place_strawberry()
        hit = True
    else:
        crapscore = crapscore + 20
        score = score - crapscore
        place_badshot()
        hit = False
\$\endgroup\$
7
  • \$\begingroup\$ Sounds like you're updating your score values in the wrong order. You want to decrease the score before you increase the crapscore and display the new values. If you show us your code we can confirm this and help you make the fix. \$\endgroup\$
    – DMGregory
    Commented Jul 7, 2021 at 13:34
  • \$\begingroup\$ @DMGregory I've edited it and posted the code, I'll now go back and see what I can do based on what you said. \$\endgroup\$
    – pythonnoob
    Commented Jul 7, 2021 at 13:47
  • \$\begingroup\$ @DMGregory Thanks! It works now! The new code is up in the main post. \$\endgroup\$
    – pythonnoob
    Commented Jul 7, 2021 at 13:53
  • 1
    \$\begingroup\$ If you've solved your problem, you can post your solution as an answer, or delete the question. \$\endgroup\$
    – DMGregory
    Commented Jul 7, 2021 at 14:37
  • \$\begingroup\$ @DMGregory how do I 'post solution as an answer' ? \$\endgroup\$
    – pythonnoob
    Commented Jul 8, 2021 at 4:18

1 Answer 1

1
\$\begingroup\$

Swap the order of the variable changes. Minus it first, then increase it to show how exactly much the player will lose.

Here's the fixed else-clause:

else:
    score = score - crapscore
    crapscore = crapscore + 10
    place_badshot()
    hit = False
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .