Discuss Scratch

nvqanh
Scratcher
58 posts

Broken "if" in Memory Game

In my memory game, there is a bug: sometimes when you click 2 cards that don't match, the game removes one of them. Please help me fix it. Thanks a lot.
nvqanh
Scratcher
58 posts

Broken "if" in Memory Game

There is this script, but it seems to be broken:
if <(item (1) of [cards opened v] :: list) = (item (2) of [cards opened v] :: list)> then
delete this clone
end
There is also “start sound” and “change effect”, but you don't need to care about them.
10goto10
Scratcher
1000+ posts

Broken "if" in Memory Game

I think you have a race condition between the code that is deleting ”cards open” and the code that is testing for the values in that list.
nvqanh
Scratcher
58 posts

Broken "if" in Memory Game

10goto10 wrote:

I think you have a race condition between the code that is deleting ”cards open” and the code that is testing for the values in that list.
I think it's not. Before I added the "delete all of " to the main script (before that the delete all was in the clone script), it already had that bug.
10goto10
Scratcher
1000+ posts

Broken "if" in Memory Game

I added an ask block before the delete all and it plays okay (well, except for the annoyance of the ask block so that’s not a fix just a debugging step).
nvqanh
Scratcher
58 posts

Broken "if" in Memory Game

10goto10 wrote:

I added an ask block before the delete all and it plays okay (well, except for the annoyance of the ask block so that’s not a fix just a debugging step).
Oh I think maybe I should add a “wait 0 seconds”. Let me check…

That doesn't work.

Last edited by nvqanh (Dec. 31, 2024 14:40:23)

nvqanh
Scratcher
58 posts

Broken "if" in Memory Game

10goto10 wrote:

I added an ask block before the delete all and it plays okay (well, except for the annoyance of the ask block so that’s not a fix just a debugging step).
I added an ask and the bug is still there.
10goto10
Scratcher
1000+ posts

Broken "if" in Memory Game

Well now I’m concerned that we are not looking at the same project because when reloaded I didn’t see an ask block in the project linked above.

I tried my patch again and it worked for me and I don’t think it’s because I’m using an iPad (no mouse).
RokCoder
Scratcher
1000+ posts

Broken "if" in Memory Game

In alignment with what has been suggested, make the wait block before deleting the items a little longer than the wait block before comparing items (maybe 0.6 and 0.5)
nvqanh
Scratcher
58 posts

Broken "if" in Memory Game

10goto10 wrote:

Well now I’m concerned that we are not looking at the same project because when reloaded I didn’t see an ask block in the project linked above.

I tried my patch again and it worked for me and I don’t think it’s because I’m using an iPad (no mouse).
Did you mean ask is this one?
ask [] and wait
nvqanh
Scratcher
58 posts

Broken "if" in Memory Game

RokCoder wrote:

In alignment with what has been suggested, make the wait block before deleting the items a little longer than the wait block before comparing items (maybe 0.6 and 0.5)
It worked!! Thank you soooo much.

Powered by DjangoBB