Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scratch game scoring bug

Tags:

mit-scratch

I'm making a paddle ball game on Scratch (just for fun), and I'm running into a problem with my scoring. If you want to look at the code I already wrote, the link to the game is https://scratch.mit.edu/projects/66541388/ . For some reason, when the game is played the score variable does not actually always change by one. It changes by a different number every time I test it. Any ideas on what the problem is or how to fix it?

Here's the core of the code:

when green flag clicked
set [Score v] to [0]
set x to (0)
set y to (0)
point in direction (pick random (-90) to (90))
forever
    if <(y position) < [-146]> then
        broadcast [gameOver v]
        stop [all v]
    end
    if <touching [Paddle v]?> then
        change [color v] effect by (pick random (1) to (1000))
        change [Score v] by (1)
        point in direction (pick random (-90) to (90))
    end
    move (10) steps
    if on edge, bounce
end
like image 475
Caroline Harlow Avatar asked May 24 '26 02:05

Caroline Harlow


1 Answers

Though both answers are correct, you can simply put the scoring in a different block of code, with a wait until <not<touching [Paddle v]>>, like this:

when green flag clicked
forever
    if <touching [Paddle v]> {
        change [color v] effect by (pick random (1) to (1000))
        change [Score v] by (1)
        wait until <not<touching [Paddle v]>>
like image 52
UnsignedByte Avatar answered May 27 '26 09:05

UnsignedByte