29 — Playlist: shuffling the order once
Shuffle in a music app does not keep picking any song at random — that would play the same song twice in a row. It mixes the order once and then plays through it. One list of songs is all you need.
Steps
Make the list of songs:
run it →set songs to list of Blue, Green, Red, Gold show songs joined by commaThey come out in the order you wrote them.
shufflemixes the order. It goes in the same place assortfrom guide 52, and it changes the list itself:
run it →set songs to list of Blue, Green, Red, Gold shuffle songs show songs joined by commaA different order every run. No song is lost or repeated — it is the same four songs in another order.
Play through the shuffled order.
with placefrom guide 21 says which song you are on:
run it →set songs to list of Blue, Green, Red, Gold shuffle songs for each song in songs with place show place show song endWait while a song plays. A pause stands in for the real playing:
run it →set songs to list of Blue, Green for each song in songs show song wait 0.5 seconds endThe whole thing:
run it →set songs to list of Blue, Green, Red, Gold shuffle songs show todays running order for each song in songs with place clear the screen show place show song wait 0.5 seconds end show that was all of them
Try it yourself
Delete shuffle songs and run it again — the order never changes. Put
sort songs there instead and it plays alphabetically. All three are one
sentence in the same place.
What you learned
shuffle <list>mixes the order at random, losing and repeating nothing.- Shuffling once and playing through is what an app actually does.
shuffle,sortandreverseare the same kind of sentence: they change the list itself.with placelets you show which song is playing.