Discuss Scratch

General_AW
Scratcher
56 posts

Can't check for bomb neighbours in a minesweeper game.

Hello lads! There's a slight issue i'm having while building logic for checking neighbouring tiles in a port of a minesweeper game. Mid-coding, i decided to run the game to check if i could swap (placeholder) costumes with numbers near mines. but the code didn't work. I then decided to replace switch costumes blocks with delete list blocks to see if it'd work, and it didn't. I tried placing this code somewhere else, but the list never got erased. Can someone help me to find out why my bombNeighbours list never gets updated?

Project file:https://scratch.mit.edu/projects/424724442/
deck26
Scratcher
1000+ posts

Can't check for bomb neighbours in a minesweeper game.

Your lists are all local to the sprites so each clone gets its own copy of the list. You probably want global lists so there's only one copy.
Nezon
Scratcher
1000+ posts

Can't check for bomb neighbours in a minesweeper game.

there is literally no script that changes the items lol
General_AW
Scratcher
56 posts

Can't check for bomb neighbours in a minesweeper game.

deck26 wrote:

Your lists are all local to the sprites so each clone gets its own copy of the list. You probably want global lists so there's only one copy.

I assume i have to do the same thing with hasBomb list, right? I'll get to it then and reply whenever something happens.
deck26
Scratcher
1000+ posts

Can't check for bomb neighbours in a minesweeper game.

General_AW wrote:

deck26 wrote:

Your lists are all local to the sprites so each clone gets its own copy of the list. You probably want global lists so there's only one copy.

I assume i have to do the same thing with hasBomb list, right? I'll get to it then and reply whenever something happens.
If you don't want the clones to have their own copies of the lists, yes. In most cases such lists are a bad idea. Other than cloned enemies having multiple items of data to keep track of or something like that I'd avoid local lists.
General_AW
Scratcher
56 posts

Can't check for bomb neighbours in a minesweeper game.

deck26 wrote:

General_AW wrote:

deck26 wrote:

Your lists are all local to the sprites so each clone gets its own copy of the list. You probably want global lists so there's only one copy.

I assume i have to do the same thing with hasBomb list, right? I'll get to it then and reply whenever something happens.
If you don't want the clones to have their own copies of the lists, yes. In most cases such lists are a bad idea. Other than cloned enemies having multiple items of data to keep track of or something like that I'd avoid local lists.

I converted my lists from local to global, and now there are some changes going on. But not the changes i wanted. Instead of checking every tile for a mine, it just checks the very first one, or the 9th tile will always report 1 bomb nearby, even when there are no mines. Should i make a new topic for this?
deck26
Scratcher
1000+ posts

Can't check for bomb neighbours in a minesweeper game.

I'm having a look but have to make sense of your code. I assume HasBomb records the positions and the neighbour list is the counts.
deck26
Scratcher
1000+ posts

Can't check for bomb neighbours in a minesweeper game.

Your ShuffleMines script is quite an inefficient method. Adding things to a list and deleting them takes a bit of work.

A simpler method is to create a list of 90 zeroes and then insert ones at random positions in the list. (pick random 1 to (length + 1))
deck26
Scratcher
1000+ posts

Can't check for bomb neighbours in a minesweeper game.

Haven't time to do more tonight but have a remix so I can check your code further.
nyankatpro
Scratcher
500+ posts

Can't check for bomb neighbours in a minesweeper game.

I think I found the problem! In the code for Neighbors Check you use the “item # of () in list” block instead of “item () in list”. The block you're using returns where the given input is in the list, and returns 0 if the input isn't on the list. Because of this, if your code is checking for a mine at, say, square 50, it will instead check to see if the number 50 is in HASBOMB, which returns 0. You can fix this by replacing all of the aforementioned blocks with “item () in list”. Hopefully this works!

P.S: In your check for the upper left corner, you use tileCount < 10 when it should be tileCount > 11
deck26
Scratcher
1000+ posts

Can't check for bomb neighbours in a minesweeper game.

I'd just come to the same conclusion as @nyankatpro - you want the item from the list not the item number.
General_AW
Scratcher
56 posts

Can't check for bomb neighbours in a minesweeper game.

@nyankatpro, @deck26, i give you my MAJOR thank you! I kinda feel dumb for making that mistake.


There is another issue with this project, however. But once i'll finish the logic, i'll post that said issue in a new post.

Last edited by General_AW (Sept. 24, 2020 20:30:21)

Powered by DjangoBB