This forum has been an invaluable resource for me so I am posting this in an attempt to "give back" to the community. (This technique might be used by many of you already but perhaps it will be new to some. It was new to me!)
The Problem:
My game has 20 or so instances of a card on the screen. To spin the card I have to sequence multiple tweens together, like this:
- Get UID of clicked on card
- Tween xscale from 1 to 0
- If tween is finished --> change sprite image to back
- Tween xscale from 0 to 1
- If tween is finished --> change sprite image to front
But because there can be multiple tweens happening at the same time the logic was getting confused. For example, before the first tween sequence had completely finished the player might have picked a new card. Now my "On finished" event would reference the wrong instance!
My Solution:
When I create a tween I now tag it with the UID of the card that was clicked on. Then I can pick the correct card by parsing the tag.
The player clicks on a card:
-> fam_cards: Tween "spin1_" & fam_cards.UID property X Scale to 1...
Then I can simply check:
+ fam_cards: On Tween "spin1_" & tokenat(fam_cards.Tween.Tags,1,"_") finished
+ System: Pick fam_cards by evaluating fam_cards.UID = int(tokenat(fam_cards.Tween.Tags,1,"_"))