Ok, so
here’s the code. I haven’t made an effort to tighten it up, so don’t be too harsh.
What I’m implementing is a klotski-style sliding block puzzle. I’ve defined the 11 blocks as characters and the 4x5 board as 20 objects. Everything has been aligned to the top left corner (of characters and board spaces).
Clicking on a block switches it to the current character. Clicking on a space executes the OnSpaceClick function with the corresponding space index, e.g. OnSpaceClick(42) for a click on the space in row 4, column 2.
The code then gets the block info, determines what moves are required, checks if those moves are possible (pseudo collision checking) and moves a single space in an available direction. Originally there was a while loop to continue until the destination was reached or no moves were available anymore (in the selected direction), but I’ve removed it. Also note that for the startAction command I’ve defined a ‘Move current character to object’ for each of the squares.
Now regardless of the code not being very pretty, it does work as intended. It’s the animations which are my problem. Due to the stacking of action commands (as elaborated by Simon) a double move (e.g. MoveTo51 followed by MoveTo41) effectively becomes a single move (i.e. MoveTo41). This is the reason I’ve removed the original While loop – only single spaces are moved per click now.
Finally, I know I’ve taken some liberties in the coding where expressions are not 100% generic, but specific to our game.