Generally speaking, I can usually overcome any programming snags with some persistence and by delving into documentation and the Internet. But this time I'm stuck.
I'm making a simple game to get students used to taxonomic classification. In the game, the player sees an organism's picture and/or common name. Beneath that it says "Kingdom: " followed by an ActionMenu[]. When the player chooses correctly from the menu, a new line is added that says "Phylum: " followed by another ActionMenu[], etc. This all works, but when it continues to class, order, family, genus, and species it does not replace the ActionMenu[] with the correct answer and it does not update the score. I suspect the issue is related to Dynamic, but I'm not sure.
Can anyone help me get unstuck? Please?
By the way, the game's not done. I intend to speed up the organism selection, add behavior for wrong answers, and give it a meaningful scoring system. I'll finish it when I get unstuck and post the complete code here.
Here is what I've got so far...
taxa = {"Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species"};
spec = Entity["Species", "Class"];
qCt = 1;
score = 0;
Print[Dynamic[spec]];
While[
Not[spec["TaxonomicLevel"][[2]] == "Species" \[And] (StringQ[spec["CommonName"]] \[Or] ImageQ[spec["Image"]])],
spec = RandomEntity["Species"]];
stats = EntityValue[spec, Join[{"CommonName", "Image"}, taxa]];
alts = Prepend[Table[Prepend[RandomSample[EntityValue[stats[[n]], "Siblings"], UpTo[6]],stats[[n]]], {n, 4, 9}],EntityList[EntityClass["Species","Kingdom"]]];
ansRt[lvl_, ent_] := (
Print[{lvl, ent}];
ques[[lvl, 1, 3]] = ent;
game[[1, 1]] = Insert[game[[1, 1]], ques[[lvl + 1]], -2];
score += 100;
qCt += 1);
ansWr[] := score -= 33;
menu = Table[ActionMenu["choose",RandomSample[Table[If[Length[alts[[n]]] >= m, If[m == 1, alts[[n, m]] :> ansRt[h2, alts[[h2, 1]]] /. {h1 -> m,h2 -> n}, alts[[n, m]] :> ansWr[]], Nothing], {m, 1,7}]]], {n, 1, 7}];
ques = Table[Row[{taxa[[q]], ": ", menu[[q]]}], {q, 1, 7}];
game = Dynamic[Column[{stats[[2]], Style[stats[[1]], 36], ques[[1]],StringForm["Score: `1`", score]}]];
TraditionalForm[Style[Dynamic[game], 24]]
Thank you in advance,
Mark