There are only six events in this project so it shouldn't take much to set up. First up, we need a few things to happen when the layout starts:
Condition
System ▶︎ On Start of Layout
Action
AdvancedRandom ▶︎ Create permutation table with 52 values starting at 1
AJAX ▶︎ Request CardNames.json (tag "LoadArray")
FaceUpCard ▶︎ Tween "ShrinkWidth" property Width to 0 in 0.5 seconds (Default, Destroy: No, Loop: No, Ping Pong: No)
This set of actions creates our permutation table, starts off the AJAX events to load the card name data and turns over the first card.
Once the AJAX request is complete, we need to load that data into the Array and update the text object:
Condition
AJAX ▶︎ On "LoadArray" complete
Action
Array ▶︎ Load from json string AJAX.LastData
Text ▶︎ Set text to "Current Card: " & Array.At(AdvancedRandom.Permutation(CardNumber),0) & newline & "Cards left in deck: " & (51-CardNumber)
These two events start off the project, so next we need to make sure you can flip through the deck of cards. Progressing through the deck is done by clicking the NextCard sprite. Though we do need to add in a couple of extra conditions to make sure you can't spam through the deck and potentially mess it up.
Condition
Mouse ▶︎ On Left Button clicked on NextCard
FaceUpCard ▶︎ Is NOT playing any Tween
System ▶︎ CardNumber ≠ 51
Action
System ▶︎ Set FirstCard to False
FaceUpCard ▶︎ Tween "ShrinkWidth" property Width to 0 in 0.5 seconds (Default, Destroy: No, Loop: No, Ping Pong: No)
The second part of the animation and the updating of the card numbers are done when the first Tween ends – though different things happen depending on whether the FirstCard Boolean is true or not.
Condition
FaceUpCard ▶︎ On Tween "ShrinkWidth" finished
Sub-Event Condition
System ▶︎ Is FirstCard
Sub-Event Action
FaceUpCard ▶︎ Set animation frame to AdvancedRandom.Permutation(CardNumber)
FaceUpCard ▶︎ Tween "GrowWidth" property Width to 128 in 0.5 seconds (Default, Destroy: No, Loop: No, Ping Pong: No)
Sub-Event Condition
System ▶︎ Is NOT FirstCard
Sub-Event Action
System ▶︎ Add 1 to CardNumber
FaceUpCard ▶︎ Set animation frame to AdvancedRandom.Permutation(CardNumber)
FaceUpCard ▶︎ Tween "GrowWidth" property Width to 128 in 0.5 seconds (Default, Destroy: No, Loop: No, Ping Pong: No)
Text ▶︎ Set text to "Current Card: " & Array.At(AdvancedRandom.Permutation(CardNumber),0) & newline & "Cards left in deck: " & (51-CardNumber)
And that's all there is to the event sheet. The project itself may be small, but it shows how you can have a non-repeating sequence of numbers thanks to the Permutation Table and how to use it in a context like a deck of cards. You could use it for all sorts, including a non-repeating number list to use for quiz questions – simply call the question number in place of the card number in this example.
Enjoy making use of Permutation Tables!