How do I analyze an array grid for 3 or more matching values

Get help using Construct 2

Post » Thu Sep 17, 2015 4:24 am

Can't be much more specific then the subject line lol. I'm trying to detect 3 or more matching values in an array grid, vertically and horizontally... then flagging the value of the x/y in the grid with -1 or something, so the entity corresponding to that point on the array can destroy itself, add points, and reset the position on the array/grid back to empty. If that makes sense... my brain hurts.
B
13
S
4
Posts: 61
Reputation: 1,028

Post » Thu Sep 17, 2015 4:58 am

i have the same question, arrays are hard, i dont know if this will help you but this piece of code works perfectly to me:

Image

With this code i can find 1 value in the array but i need to find another value in the array and if two values are matching then -> action (spawn enemies in this case)

i am reading this:

http://www.gamechange5.com/devpage/10

maybe the answer its here, maybe we need nested loops.. i am still reading
B
9
S
3
Posts: 142
Reputation: 1,108

Post » Thu Sep 17, 2015 5:28 am

I think I might have the wrong idea of how loops work, as well as local variables. I wish the debug panel could should array values in a grid or something..
B
13
S
4
Posts: 61
Reputation: 1,028

Post » Thu Sep 17, 2015 6:46 am

powerwaffle wrote:I think I might have the wrong idea of how loops work, as well as local variables. I wish the debug panel could should array values in a grid or something..


Yes, the debug panel helps you to check if the array is modified, but the next array tool helps me a lot to understand and handle the arrays:

array-contents-editor-2d-3d-beta_t120926?&hilit=array

I partially solved my problem with the array, check the part of the code that solves my problem, maybe can help you too:

Image

Now i can find two values in the array and if are matching then spawn new enemies, but sometimes didn't work because sometimes just spawn 4 objects instead 5.
B
9
S
3
Posts: 142
Reputation: 1,108

Post » Thu Sep 17, 2015 7:45 am

powerwaffle wrote:Can't be much more specific then the subject line lol. I'm trying to detect 3 or more matching values in an array grid, vertically and horizontally... then flagging the value of the x/y in the grid with -1 or something, so the entity corresponding to that point on the array can destroy itself, add points, and reset the position on the array/grid back to empty. If that makes sense... my brain hurts.


Sounds to me like you're looking for Match-3 mechanics. Rexrainbow has made an example using his own plugins. It's very flexible, but may not be too well suited for beginners.

I also made a little plugin using the jMatch3 lib. It is less flexible, but easier to use in my opinion.

Of course you can do this purely with events. I've done several Match-3 engines this way. Basically you just loop through a row/column (pretty much like Majinboo shows with the For-loop), have a variable hold the number of matches, which you get by comparing to the previous piece. If you reach a number of three are greater you have a match.
B
23
S
6
G
10
Posts: 1,041
Reputation: 7,553

Post » Thu Sep 17, 2015 4:08 pm

I can't seem to figure out how to pull a value from an array at a 2D position, like variable = (value @ x-3/y-5)

edit:
https://www.scirra.com/tutorials/307/ar ... ers/page-4

hahaha wow I suck
B
13
S
4
Posts: 61
Reputation: 1,028

Post » Thu Sep 17, 2015 10:27 pm

Can any of you see a bust in logic in this? I can't seem to figure out why this wont work...
Image
B
13
S
4
Posts: 61
Reputation: 1,028

Post » Thu Sep 17, 2015 10:44 pm

Just thought I'd mention that you can do loopindex("loopheight") to get the value of a specific loop. That way you won't have to store those values in local variables.
B
45
S
21
G
65
Posts: 1,115
Reputation: 38,221

Post » Fri Sep 18, 2015 12:40 am

Are the events in the loop actually cycling or is the engine duplicating the function with each having a progressing loopindex value - running at the same time - making counting cycles with a local variable pointless.
B
13
S
4
Posts: 61
Reputation: 1,028


Return to How do I....?

Who is online

Users browsing this forum: beohs, divsyntax, tunepunk, Yahoo [Bot] and 8 guests