# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### Newcomers AppGameKit Corner / Get Sprites contained in matches

Message
Posted: 1st Jul 2020 02:40
So I'm using a example code for a match 3 game.

It's checking for matches in cell positions.

But after the check only one sprite= the amount .

It's telling me there's 4 matches, but only one Sprite is holding data for the match.

So if there was 4 matches then only one sprite=4. So I can only update sprite 4 to be destroyed. I need to get all the sprites in the match.

Here's the code for the check.

Posted: 1st Jul 2020 03:44 Edited at: 1st Jul 2020 03:46
all that you need is already within the code. and, it's not in the "1 sprite", but within the array where matches are tagged "1" for future reference (and said "destruction" ).

follow the code that scraggle generously provided, line by line, and learn what's going on before trying to move forward.

Quote: "I wish I could do something to show my appreciation"

following the above advice would be exactly that
Posted: 1st Jul 2020 04:34 Edited at: 1st Jul 2020 04:37

I looked at every line of code and even read just about every help page per command.

I tried saying something alone the lines of

ChosenSprite=board[x,y].qtyMatches

Print(ChosenSprite)

Now when I do this or even try to destroy a Sprite only one sprite is destroyed. The first Sprite. I've gone over this code all day.
Posted: 1st Jul 2020 05:51
fair enough

so, looking for .qtyMatches of 3 or more could be the start of it. IE, if a particular x,y = 3, then the next 2 must be the remaining matches. if x,y = 4, then the next 3, etc.

the problem is, which axis (or axes) does the match3 fall in? since you know where they start and the quantity, you know how far to check in both directions to determine the remaining sprites involved.

hope that helps?
Posted: 1st Jul 2020 06:54
And that's why I believe that I'm having a hard time.

When I check to see what number is a match.

Non matching sprites =1 so I can hide matching sprites from 2 on.

All sprites=1 unless they match. Then all the sprites in the match=1 but one, and that one sprite in the match= the total number of matches.

I understand what you are saying truly.

But my code is the same as the example, nothing changed. I get matches, but the numbers on the matches are wrong.

Like a example.

I get three matching sprites, two of those sprites are numbered 1 then the next sprite is numbered 3. But then two sprites match and one is 1 and the other is 2.

And You can only get a match if three sprites match.

My brain hurts lol.
Posted: 1st Jul 2020 14:18
i'm sorry that i jumped to conclusions that you had not studied the code where it's obvious that you have.

and, i wish i had more time to lead you further but i have to be to work in 15 minutes

if no one else has by the time i get back (probably 12 hours...), i'll try to lead you further with the "if a particular x,y = 3, then the next 2 must be the remaining matches. if x,y = 4, then the next 3, etc." part from above.

Posted: 1st Jul 2020 15:28
Thanks, I have all my sprite positions saved into a slot array.

Bear with me,I'm new to appgamekit.

I'm ketching on.

Can't wait to hear from you soon.
Posted: 1st Jul 2020 16:18 Edited at: 2nd Jul 2020 12:05
Here you go:

qtymatches is now an array
0 for horizontal and 1 for vertical. So you can now see how many matches there are in each direction.

Edited to add the media attached in the previous thread in case anyone is seeing it here for the first time and wants to follow along

#### Attachments

Posted: 1st Jul 2020 21:28
Wow, than you, I'm trying it out and will get back to you soon.

This is cool
Posted: 2nd Jul 2020 01:14
Ok so now I am getting matches for up and down but the same thing is happening.

Only one sprite is equal to the sprite quantity.

The rest in the match equal 1

But I'm starting to get it somewhat.

If one sprites quantity is like 3 or over that is the starting point to check for matches.

Now that is the hard part.
Posted: 2nd Jul 2020 06:34 Edited at: 2nd Jul 2020 12:06
Instead of providing the code again, I'll just tell you what you need to do and you can work it out from there.

Firstly, create a function called DeleteMatches(). You will use that in place of ShowMatches() which is only meant as a debug thing anyway.
Inside the function you need to loop through every cell in the board[] array and check for horizontal matches >=3.
When you find one, create a loop from zero to qtyMatches-1 then delete all sprites in the board at x+loopcounter.
Then do the same for the verticals.

You're going to encounter 2 problems.
Imagine you have a horizontal match and a vertical one that cross each other. You delete the horizontal matches, then when you try to delete the verticals the code will crash with an error that the sprite does not exist!
To get around that; before you delete the sprite, check that it firsts exists.

The second problem is that the sprites are purely there for the player to visualise the board (obviously) but the computer doesn't care about them at all and 'sees' the board based on the data in the board[] array which is still intact. You can check that by calling CheckMatches() after deleting the sprites, the same matches will still be reported.
You need to delete the data in board[] that corresponds to the sprites you deleted but you can't do it in the same loop because:
Imagine you have horizontal and vertical matches that start on the same cell. If you delete them as you find them then when you delete the horizontal data, the vertical data from the start cell will go with it and the remaining vertical cells will not be removed.
The solution is to delete the sprites as above and then create a second loop through all cells in the board but this time check for cells without sprites in them. When you find one, you delete the cells data.
Quote: "Now that is the hard part."

Actually no, but the next part is quite tricky though.

Good luck
Posted: 2nd Jul 2020 06:58
Ok, I'll see what t can do, I already an just setting my sprites invisible if hungry and Visable if full. So no deleting required. I'll let you know how it goes.

Thanks for the help.
Posted: 2nd Jul 2020 21:48
Ok I pretty much figured this out.

For the matches all I needed to do was create my own idetifier array to count each match so each sprite gets there own match number. All sprites start off being identified by number 1. But then if there's anything match it incs that . If the count is over two then there's a match, a separate condition.

Then everything else after that is converted to 0.

In order to get this was converting my match sprites to the same number. I choose 100 because it's simple.

Then after that match happens everything goes back to normal and all the sprites left go back to 0.

Thank you guys for the help.
Posted: 2nd Jul 2020 21:54
That's a very strange way to do it but if it works, it works
Posted: 3rd Jul 2020 03:01
Well I tried what you suggested and it does not work, here is what I did and for some reason it does nothing. So I changed it and it works sometimes.

Posted: 3rd Jul 2020 08:08 Edited at: 3rd Jul 2020 08:14
Quote: "Well I tried what you suggested and it does not work"

In that case you didn't do it correctly. I just converted what I said into code and it works perfectly.
I would provide the code function to show you but the code it uses the follows on from the latest code I provided which uses qtyMatches as an array, and I can see from the function above that you are not using the latest code so it won't work.

Instead, I'll talk about what you are doing wrong in the code you've provided:
Here's your code with the indentation fixed so that the loops are easier to follow:

You say it 'works sometimes'. I find that hard to believe because that code as it is shouldn't do anything at all.
The reason it shouldn't do anything is because of this part:

You are looping x from ZERO to BOARD_SIZE but the code will only run through your while loop if x > BOARD_SIZE - Which it never is. So nothing will be executed within the while loop.

Let's ignore that part for now though and examine what you are trying to do inside the while loop (which as said above, will never be called):

Here you are not using the qtyMatches array so unless you change that to the latest code I provided the first thing you'll need to do is establish which direction the matches are in. That's an extra step that you can avoid by using the qtyMatches array instead.
However, what you are doing is finding the cell that starts a match of 3 or more and then checking to see if there is also a cell that starts a match of 3 or more in the cell one place to the left of it. The only time that could happen is if the start of a vertical match occurs directly to the left of the start of another vertical match or a horizontal match.
The second problem with it is that if the start of a match occurs in the first column the code will then crash with an error because you are trying to check a cell that doesn't exist off the left side of the board.
Posted: 3rd Jul 2020 08:31
I'm sorry, I am using the new code you provided, I was just going back in a new test to see if I could figure it all out.

I have two applications, the newest one, and the old one to learn with.

I read so much on this issue that i'm a little lost to be honest.

If I try to say while x < BOARD_SIZE

it gives me a warning that the array size is not matching.

So that confused me.

But when i change it to be over the board size it runs, but does nothing.

What I meant as it works sometimes is what I am doing as far as counting with my own identifier array.

So i am lost.

To learn, What I need is the code that works, and the explanations on why it works.

Trying to figure it out for myself is not good because I do not know the code that well.

But I am trying.

Posted: 3rd Jul 2020 08:46
Quote: "What I need is the code that works, and the explanations on why it works."

Here is the code that works. I'm setting the sprites as non-visible rather than deleting since that was your preference.
The reason the delete function works is because it does exactly what I suggested in English (not code) above.

Go through that code and try to learn what everything is doing and why. Only when you feel you understand it fully should you move forward with the next step.
It was never my intention to write a match 3 game or write a tutorial, but that seems to be happening. I'll keep helping if you need it but I'm reluctant to continue providing complete code. I'd rather see what you are doing and point out where it can be improved.
Posted: 3rd Jul 2020 09:02
Well, it works, I will take a couple days to learn from it, do more testing on other example to see why and how it works.

I love your help on this, i'm learning more and more.

It is funny, while I just tested it, and the matches where hidden, I laughed.

I usually do my own coding, I don't ask for help unless I am so dumb to the problem and frustrated.

A tutt would be helpful for this type of game, I would buy your tutt, that's a fact.

Posted: 3rd Jul 2020 23:15
So I have learned that you can use any array for calls on grabbing information. That you can count sprites in screen positions and also why it works.

Now I need to learn how to get only the sprite above the empty sprite when to fill the empty with it's information.

I think I have a good way.

I will post it when I get it.

Hopefully it will work.
Posted: 4th Jul 2020 07:41
Check the code I gave you again.
The sprite are irrelevant, the checks don't care what the sprites look like, the checks take place on the cells style not sprite.
board[x,y].style
Posted: 4th Jul 2020 21:58 Edited at: 4th Jul 2020 21:59
Yes, that is true

So I tried doing this , and it worked but the whole top row come down when slots under them are calling for data.

lol, its kind of funny.

Posted: 4th Jul 2020 22:07 Edited at: 4th Jul 2020 22:27
And also how do i position sprites to there own position lol, Here is what I am doing, im sure I will figure out the code above, it is close, but this stomps me.

Let me Explain

If the current sprite i'm moving over to switch with the other sprite is moved to far over the next sprite pos, then a player can move the sprite anywhere.

Posted: 4th Jul 2020 22:34 Edited at: 4th Jul 2020 22:39

we can "evaluate" within command (and function?) parameters?

IE: If board[x,y].qtyMatches[k] >= 3 then (parameter) = 1 (else 0) ?
Posted: 4th Jul 2020 22:57
I'm in bed about to sleep so I'll look at GCH's code in the morning but as for VN, yes, that's it exactly.
The second part is evaluated to TRUE(1) or FALSE(0) and applied to the 2nd parameter of SetSpriteVisible()
Posted: 5th Jul 2020 00:28
Scraggle

ok, I figured this out after a couple tests. this is what I did .