Had another go at it so now the logic is a bit more understandable and fits within 25 events.
When you click on a tile it does a search for valid moves from that tile to other matching tiles. the path from one tile to another can only bend twice and the path has to go through an empty space first.
Then when you click on a matching tile it destroys the tiles and draws the path.
If you want to see the pathfinding in action make the marker sprite initially visible in the editor.
It's trivial to change the number of unique tiles, but just be sure there are enough tiles on the board so there can be pairs.
dropbox.com/scl/fi/gpd6ss46cm1a7vfb469ev/onet2.capx