Find actors next to others with same attributes?
I want to create a rule that finds actors that possess the same attributes. I have a grid of 60 actors. Some are black and some are gray. I want to be able to find black actors that are adjacent to other black actors and link them. For example if three black actors are adjacent to each other they would be linked in a chain of three. A sample grid of this situation is shown below.
GGGGG
GBBBG
GGGGG
The grid below would be a chain of 5 because 5 Black actors would be adjacent.
BGGGG
BBBGG
BGGGG
Within the overall grid there may be 15 instances of linked blocks. Should I make 15 game attributes to measure link length? Or should I use self attributes?
Also, is there a way I can quickly determine if a another black actor is next to any other black actors?
Comments
I would use a table to store the color values. Then you can compare table values by number (e.g. row 2 column 3 vs. row 2 column 4, etc.).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
My data is tables. Do I use the table search to accomplish this? Or does the logic below work?
Let's say the table values are as follows:
1 represents black
0 represents gray
If row 1 col 1=1 and row 1 col 2=1
If link > 0r = 1
Then change link to link +1
If row 1 col 1 =1 and row 1 col 2= 0
Then change link to 1
You can compare them manually as you suggested or use a tableMerge() function. For example if you were looking for the pattern 111 and your table looked as follows:
01110
10010
11001
Then you could merge each row (assuming you are using a text attribute to merge into) and check to see if any rows contain "111".
There are some sophisticated ways to do this using textSubStr() and other text functions so you might want to dive into those as well.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User