This time I will go a little bit deeper and finish my bird song quiz app.
Basic functionality is to randomly get six bird sounds from my media list on the phone, display all six and play one of them letting the user guess which one is right. After choosing the app will tell you if it was correct.
In the last part we started out with this to get a random song:
var mysongs := media→ songs
var chosensong := songs→random
This time we do the same stuff but six times with a a while clause that adds stuff to a collection.
First we add the chosen song:
var quizlist:=collections→create string collection
while x < 5 do
var decoy := ▷getbirdname(songs→random→name
if quizlist→contains(decoy) then
x := x+1
As I want a bird song quiz I have to convert the mp3-name (for example white-tailed swallow.mp3) to a bird name. I do this by removing the .mp3 from the name together with all numbers I can find (sometimes I have many numbered sounds for a bird). This is done in getbirdname and the symbol ▷ means that it calls a function that returns the bird name from the mp3 file name.
The function looks like this:
private atomic action getbirdname(s:string)
Simple regex to get rid of the digits and then I just remove the .mp-part and return the name.
Then I show the names from the quizlist and plays the chosen one on my phone with:
"Choose bird:"→post to wall
□ chosen:= -1
while □ chosen < 0 do
□ chosen := wall→pick string("Which bird is this?", "Choose an alternative.", quizlist)
if quizlist→at(□ chosen)→equals(▷ getbirdname(target→name)
"Correct"→post to wall
"Incorrect"→post to wall
▷ getbirdname(target→name)→post to wall
The □ chosen means that it can save the result between rounds as a global persistant variable that can be stored in the cloud.
Oh by the way....
|the symbol □ looks like this with a bit magnification:|
I've just touched on what you can do with touchdevelop (try for example language→speak text("en-US", "female", ▷ getbirdname(chosensong→name)), but since I still haven't found any customer who wants his business system written in the language I will move on to graph databases next time.