Discuss Scratch

EIephant_Lover
Scratcher
500+ posts

Ignoring Code Bug

So, I was doing a clone experiment and came upon a number of glitches. The project can be found here: https://scratch.mit.edu/projects/213700920/
The main problems were that either I could not go from red to yellow to blue as desired, or that both red and blue would show at the same time.
All three sprites have the same code but with different variables and messages (between red, blue, and yellow).
I added blocks like this:
when green flag clicked
forever
if <(red showing?) = [0]> then
hide
end
end
This fixed the problem of the red and blue showing at the same time. The bug, though, is that when executing this command (without previously mentioned blocks):
when [space] key pressed
if <(blue showing?) = [1]> then
set [red showing?] to [1]
set [yellow showing?] to [0]
set [blue showing?] to [0]
broadcast [hide blue]
broadcast [hide yellow]
end
It would completely ignore the “if <blue showing = 1> then” block. “Even if ”blue showing?" equaled 0 (and I checked throughout), it would still execute the script. This script was inside the red sprite, along with a block that said:
when I receive [hide red]
hide
I was able to fix this problem, but it still made no sense that it did not work - I checked and checked and checked and I don't think I was missing anything; that there was a bug with Scratch (I have had similar problems before).

The second problem was that the code would not convert from red to yellow to blue. It only went from red to yellow to red, and back again. I never had a script that let red run its scripts. In fact, I had an “if <> then” block that did not allow the script to run, but Scratch just ignored it. Somehow, the red overrode the blue even though I had blocks that stopped red from running. I was able to get around this code from changing the "when key pressed" throughout them, but every sprite had to have their own function (such as red needs the left arrow, yellow needs the right arrow, and blue needs the up arrow). I don't know why it wouldn't work when all were space. It would just change from red to yellow to red to yellow (as mentioned before). The weird thing was, if I were to click on the script itself, it would execute perfectly; red and yellow would be hidden and blue would show. It should have worked anyway. I have left this bug on the project so you can see for yourself. (I have also had similar problems to this before, where it does not work in the project when run normally but does work when the code itself is clicked.)
I know I can work around the problems, but it is annoying to have to click left right up, left right up, left right up over and over again. I wish that I could just click space.

My main problem is that these codes should work, but they just don't. I don't see a bug (in my code) anywhere, and there is no hidden code. I believe that Scratch itself is the one with the bug.

Thanks for viewing

My browser / operating system: Windows NT 10.0, Chrome 65.0.3325.181, Flash 29.0 (release 0)

Last edited by EIephant_Lover (April 3, 2018 13:14:25)

PowerSnatch
Scratcher
100+ posts

Ignoring Code Bug

Hello!

I fixed the problem by creating a variable. Here is the project. It's probably not very efficient, but it works. Please point out any more problems you encounter.

Last edited by PowerSnatch (April 2, 2018 22:50:12)

Paddle2See
Scratch Team
1000+ posts

Ignoring Code Bug

Let's try this in “Help With Scripts” before we declare it a bug. Very often, there is something in the scripts that causes the behavior.
mstone326
Scratcher
1000+ posts

Ignoring Code Bug

We can help. Can you make your original post more concise so we know exactly what to look for? I have read it several times but am not getting the idea straight and I am also not seeing anything about clones as mentioned in the first part. I am confused where to start helping. But am willing to help.
Scratch-Minion
Scratcher
1000+ posts

Ignoring Code Bug

PowerSnatch has made a fix.

I will explain what the problem was.

You have 3 “when space key pressed” scripts, one in each colour sprite.

The 3 “when space key pressed” scripts are not executed simultaneously, but one after the other.

The Blue “when space key pressed” script happens to be executed first (the reason, believe it or not, is that it was the last sprite you moved in the editor).

Suppose the Yellow sprite was showing:
The Blue “when space key pressed” script changes blue showing? to 1.
Then the Red “when space key pressed” script runs, detects blue showing? = 1 and immediately changes red showing? to 1.

That is why you don't see the Blue sprite and clones.


As an experiment you can show and move the Red or Yellow sprites in the editor. Then the 3 “when space key pressed” scripts are executed in a different order and the project will behave differently.

Last edited by Scratch-Minion (April 3, 2018 03:27:21)

EIephant_Lover
Scratcher
500+ posts

Ignoring Code Bug

Paddle2See wrote:

Let's try this in “Help With Scripts” before we declare it a bug. Very often, there is something in the scripts that causes the behavior.
The reason I've posted it here was because I have had a problem similar in other projects (but with different code). The problem was mainly that the code that should work doesn't work. I already found ways to fix the problem, but it is still a bug.
The other “bug” is that if I were to click on the code itself to execute the command (the ones with the:
when [space] key pressed
blocks), they would work as if I had pressed space and executed the command - following the “if <> then” block. The script should be executed the same way when the space key was pressed, but that is when the bug comes in. It just ignores blocks for no reason.
Even more, it goes from red to yellow to red to yellow, and I never put a block in that told it to do that, or that should even allow it to do that.
But @PowerSnatch made a fix and @ScratchMinion explained the problem, although I still think that the part about which one was most recently moved goes first is pointless and that Scratch should remove this feature in Scratch 3.0.
EIephant_Lover
Scratcher
500+ posts

Ignoring Code Bug

mstone326 wrote:

We can help. Can you make your original post more concise so we know exactly what to look for? I have read it several times but am not getting the idea straight and I am also not seeing anything about clones as mentioned in the first part. I am confused where to start helping. But am willing to help.
The clones are not the problem; the behavior of the clones and which way they move works as I desire it to.
Look at my most recent post as a reply to @Paddle2See - I explain exactly what the bugs are there, but more to-the-point.

Last edited by EIephant_Lover (April 3, 2018 13:06:05)

EIephant_Lover
Scratcher
500+ posts

Ignoring Code Bug

Scratch-Minion wrote:

PowerSnatch has made a fix.

I will explain what the problem was.

You have 3 “when space key pressed” scripts, one in each colour sprite.

The 3 “when space key pressed” scripts are not executed simultaneously, but one after the other.

The Blue “when space key pressed” script happens to be executed first (the reason, believe it or not, is that it was the last sprite you moved in the editor).

Suppose the Yellow sprite was showing:
The Blue “when space key pressed” script changes blue showing? to 1.
Then the Red “when space key pressed” script runs, detects blue showing? = 1 and immediately changes red showing? to 1.

That is why you don't see the Blue sprite and clones.


As an experiment you can show and move the Red or Yellow sprites in the editor. Then the 3 “when space key pressed” scripts are executed in a different order and the project will behave differently.
I tried the experiment - you are completely right. If I were to move the yellow sprite and press space, it'd change to blue. If I pressed space again (without really moving blue), it just flashed and the blue color stayed. If I moved the blue, it'd switch to red and the same thing would happen, as it did with yellow. I really don't see why this feature is in Scratch - I hope they remove it in 3.0. Thanks for explaining the problem so thoroughly.

Last edited by EIephant_Lover (April 3, 2018 13:12:18)

deck26
Scratcher
1000+ posts

Ignoring Code Bug

EIephant_Lover wrote:

Scratch-Minion wrote:

PowerSnatch has made a fix.

I will explain what the problem was.

You have 3 “when space key pressed” scripts, one in each colour sprite.

The 3 “when space key pressed” scripts are not executed simultaneously, but one after the other.

The Blue “when space key pressed” script happens to be executed first (the reason, believe it or not, is that it was the last sprite you moved in the editor).

Suppose the Yellow sprite was showing:
The Blue “when space key pressed” script changes blue showing? to 1.
Then the Red “when space key pressed” script runs, detects blue showing? = 1 and immediately changes red showing? to 1.

That is why you don't see the Blue sprite and clones.


As an experiment you can show and move the Red or Yellow sprites in the editor. Then the 3 “when space key pressed” scripts are executed in a different order and the project will behave differently.
I tried the experiment - you are completely right. If I were to move the yellow sprite and press space, it'd change to blue. If I pressed space again (without really moving blue), it just flashed and the blue color stayed. If I moved the blue, it'd switch to red and the same thing would happen, as it did with yellow. I really don't see why this feature is in Scratch - I hope they remove it in 3.0. Thanks for explaining the problem so thoroughly.
It's not something to be fixed - scripts don't run all at the same time so some will always run sooner than others that appear to run at the same time. It's part of your job as coder to manage that.
Scratch-Minion
Scratcher
1000+ posts

Ignoring Code Bug

deck26 wrote:

It's not something to be fixed - scripts don't run all at the same time so some will always run sooner than others that appear to run at the same time. It's part of your job as coder to manage that.

I agree completely with deck26. It is not a bug. It does not need to be fixed.

A computer only runs one script at a time.
If there are several scripts to be run when the space key is pressed, we as programmers must write code to make things happen in the right order.

One possibility in your project is to have only one “when space key pressed” script; check which colour is currently showing; and then do a broadcast(s) to update everything.

EIephant_Lover
Scratcher
500+ posts

Ignoring Code Bug

Scratch-Minion wrote:

deck26 wrote:

It's not something to be fixed - scripts don't run all at the same time so some will always run sooner than others that appear to run at the same time. It's part of your job as coder to manage that.

I agree completely with deck26. It is not a bug. It does not need to be fixed.

A computer only runs one script at a time.
If there are several scripts to be run when the space key is pressed, we as programmers must write code to make things happen in the right order.

One possibility in your project is to have only one “when space key pressed” script; check which colour is currently showing; and then do a broadcast(s) to update everything.

Okay, maybe it's not a bug, I guess…
but I still don't like it
Scratch still ignores code though sometimes, running it when it shouldn't…
and making it work when clicked directly.
Thank you guys, I'd say the problem is resolved (mostly).
deck26
Scratcher
1000+ posts

Ignoring Code Bug

If you think Scratch is running code when it shouldn't share the project when it happens and post a new topic. I'm sure we'll be able to find what you've overlooked.
blast175
New Scratcher
1 post

Ignoring Code Bug

I have a tower defense game and the towers have an individual “stress” variable, and if it reaches 100, you can click it, and it releases a powerful attack.
Recently, all the stress variables did nothing. This is not the first time this has happened to me. I need to know what to do when this happens.
EIephant_Lover
Scratcher
500+ posts

Ignoring Code Bug

blast175 wrote:

I have a tower defense game and the towers have an individual “stress” variable, and if it reaches 100, you can click it, and it releases a powerful attack.
Recently, all the stress variables did nothing. This is not the first time this has happened to me. I need to know what to do when this happens.
Hi there!
Please post a new thread when you have a bug to report - thank you!

(I'll close the topic now.)

Powered by DjangoBB