Weird errors with 2d arrays

The title says it all… I am getting some typing errors that are hard to fix in blocks. I tried searching up the error but I couldn’t apply the answers to this project.

2 Likes

There are a few things happening here. When working with arrays, you always should give them an initial form in on start so that the compiler knows the type of array each variable contains. So, something like this:

I ran into a mismatch error, though, and I’m not sure what you meant to do.

In the mouse event handler, you set the variable territory to be an array of numbers:

In your mapThis() function, though, I think you’re expecting your array to be a two-dimensional array:

This is as far as I got. Drag and drop the image into your editor to pick up where I left off, if you like. Give a shout if you need more help.

2 Likes

Yeah sorry… I fixed this but had a whole bunch of errors due to e. findIdx or something. Probably to do with the not initialising the array type. I couldn’t delete the topic so I just left it. That is helpful though, thanks.

1 Like

Now I have a problem… You can see when clicking to choose your spot, then trying to get new land with another click, that it goes in a line. I am trying to update border to all of the places that have at least one bit of land around them. It seems to only be doing calculations on the most recent territory, which should include every single territory pixel. I really have no clue what is going on, as the only place I am changing border is in the border function. I would really appreciate your help on this :slight_smile:

2 Likes

I have a feeling one of your problems is here, in the borders() function:

At the beginning of each iteration of the loop, you’re clearing out the border array. I’m pretty sure you don’t mean to do that. Move that to the top of the function, outside of the for element loop.

See if that helps!

1 Like

I feel really stupid… I must of accidentally put it in the wrong place when I changed the code, as it was working before. Thanks so much!

1 Like