Discuss Scratch
- spyrofan
-
74 posts
Orb Matching
Okay i have number 1 im not sure about 2 and i can't figure out how to do 3 have a look at how i made the list in the project in the sprite called matching
- flutehamster
-
500+ posts
Orb Matching
Okay, I think now you have to put a script in each sprite to set the orb types. Light would be one number, poisen another, etc…
Tell me if it works.
Tell me if it works.
- deck26
-
1000+ posts
Orb Matching
I can't do anything now - 22.20 in the UK. I'll try to have a look tomorrow.
But the basic idea is that you don't need lots of separate variables if you use a list. You can even use the same custom block to check for three in a line - you just need a current cell and an increment value. For horizontal lines the increment is 1 but for vertical lines it is the number of cells in a row. If you're already less then 3 from an edge there's no point checking.
My point is that by using a grid you can hugely simplify the checking.
For example, for cell 10 (using my earlier grid) you can work out which cells you need to check for a line of 3. You don't need to check in every direction though - if you start from the lowest numbered cell then by the time you've checked for a vertical line starting from the first line then when it comes to check the second row you don't need to think about a vertical line where the current cell is a middle cell in a vertical line. Same applies for a horizontal line, you only check from one direction.
I hope that's clear but it's obviously hard to explain in words. I may create a demo.
But the basic idea is that you don't need lots of separate variables if you use a list. You can even use the same custom block to check for three in a line - you just need a current cell and an increment value. For horizontal lines the increment is 1 but for vertical lines it is the number of cells in a row. If you're already less then 3 from an edge there's no point checking.
My point is that by using a grid you can hugely simplify the checking.
For example, for cell 10 (using my earlier grid) you can work out which cells you need to check for a line of 3. You don't need to check in every direction though - if you start from the lowest numbered cell then by the time you've checked for a vertical line starting from the first line then when it comes to check the second row you don't need to think about a vertical line where the current cell is a middle cell in a vertical line. Same applies for a horizontal line, you only check from one direction.
I hope that's clear but it's obviously hard to explain in words. I may create a demo.
- flutehamster
-
500+ posts
Orb Matching
That makes sense, but I'll need the demo. It's hard making it into a list because of the way the project is designed. It doesn't use 1sprite, costumes, and clones to make it… Maybe I'll make an example project… I can't do anything now - 22.20 in the UK. I'll try to have a look tomorrow.
But the basic idea is that you don't need lots of separate variables if you use a list. You can even use the same custom block to check for three in a line - you just need a current cell and an increment value. For horizontal lines the increment is 1 but for vertical lines it is the number of cells in a row. If you're already less then 3 from an edge there's no point checking.
My point is that by using a grid you can hugely simplify the checking.
For example, for cell 10 (using my earlier grid) you can work out which cells you need to check for a line of 3. You don't need to check in every direction though - if you start from the lowest numbered cell then by the time you've checked for a vertical line starting from the first line then when it comes to check the second row you don't need to think about a vertical line where the current cell is a middle cell in a vertical line. Same applies for a horizontal line, you only check from one direction.
I hope that's clear but it's obviously hard to explain in words. I may create a demo.
- spyrofan
-
74 posts
Orb Matching
it does have clones and it does have each position set to a number that determines the orb that shows
- deck26
-
1000+ posts
Orb Matching
https://scratch.mit.edu/projects/75428464/ is my first stab at this. I have limited time to do more so wanted to show you the basics.
So at the moment I randomly assign jewels to the grid and then randomly change one of them once a second. That's just to give the idea of how to manage this using clones and a grid and a list of costumes.
As you'll hopefully see it's so much simpler than your version - far fewer variables and scripts so much easier to manage things and generalise the code.
I'll do more when I get time but if you have any queries or want me to address anything specific let me know.
So at the moment I randomly assign jewels to the grid and then randomly change one of them once a second. That's just to give the idea of how to manage this using clones and a grid and a list of costumes.
As you'll hopefully see it's so much simpler than your version - far fewer variables and scripts so much easier to manage things and generalise the code.
I'll do more when I get time but if you have any queries or want me to address anything specific let me know.
- flutehamster
-
500+ posts
Orb Matching
https://scratch.mit.edu/projects/75428464/ is my first stab at this. I have limited time to do more so wanted to show you the basics.
So at the moment I randomly assign jewels to the grid and then randomly change one of them once a second. That's just to give the idea of how to manage this using clones and a grid and a list of costumes.
As you'll hopefully see it's so much simpler than your version - far fewer variables and scripts so much easier to manage things and generalise the code.
I'll do more when I get time but if you have any queries or want me to address anything specific let me know.
This should work as a great base to a game. The orbs switch because of this code:
repeat (30)
replace item (pick random (1) to (30)) of [costume v] with (pick random (1) to (6))
end
In the main script and this code in the
when I start as a clone
script.
forever
switch costume to (item (cloneID) of [costume v])
end
- spyrofan
-
74 posts
Orb Matching
Thank you ummm i was wondering it can check one match on the screen but can you have it check 3 or 4 matches
- deck26
-
1000+ posts
Orb Matching
It can check multiple matches but you'd need to add variables or a list or something to keep track of them. Or you could have it try to find the longest line.
Basically where my script repeats until length > 2 is what makes it stop after the first line of identical symbols. Take that out wherever it appears and it will keep searching but at the moment will only show one so the bit that marks the line would have to use clones to do so and have to be moved to an earlier point in the script.
I'll add some comments to the script to see if that helps you understand but am otherwise finished for tonight.
Basically where my script repeats until length > 2 is what makes it stop after the first line of identical symbols. Take that out wherever it appears and it will keep searching but at the moment will only show one so the bit that marks the line would have to use clones to do so and have to be moved to an earlier point in the script.
I'll add some comments to the script to see if that helps you understand but am otherwise finished for tonight.
- spyrofan
-
74 posts
Orb Matching
okay so deck26 has it able to check 1 match on screen but what if there are multiple on screen
- flutehamster
-
500+ posts
Orb Matching
OK, I'm on vacation, and then school, so I'll make it eventually. You might want to try this:
Calculate max number of combinations: I bet it is 12
Then:
And I'll do the rest later
Calculate max number of combinations: I bet it is 12
Then:
when I receive [check v]
repeat (12)
create clone of [myself v]
end
when I start as a clone
do custom block :: custom
And I'll do the rest later
- deck26
-
1000+ posts
Orb Matching
My project now has another sprite with a modified script that finds all occurrences of a row of 3 or more. It was a trivial change which took me less than 10 minutes.
- spyrofan
-
74 posts
Orb Matching
Okay thank you now can you have the orbs broadcast the number of the orbs plus what type
- spyrofan
-
74 posts
Orb Matching
Okay yes but what about the type because i need it to distinuguish a 3 fire combo from a 3 dark combo
- deck26
-
1000+ posts
Orb Matching
When a line is detected the scripts knows the length and the starting cell. From the starting cell you can get the costume of the orb by looking up the cell number in the list. So you have everything you need.
- spyrofan
-
74 posts
Orb Matching
okay im sorry i feel like my ignorance is a bother but can you give me a small script on how to do that